+ VikMapsLayer *vml = VIK_MAPS_LAYER(values[MA_VML]);
+ VikViewport *vvp = VIK_VIEWPORT(values[MA_VVP]);
+
+ // I don't think we should allow users to hammer the servers too much...
+ // Delibrately not allowing lowest zoom levels
+ // Still can give massive numbers to download
+ // A screen size of 1600x1200 gives around 300,000 tiles between 1..128 when none exist before !!
+ gchar *zoom_list[] = {"1", "2", "4", "8", "16", "32", "64", "128", "256", "512", "1024", NULL };
+ gdouble zoom_vals[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024};
+
+ gint selected_zoom1, selected_zoom2, default_zoom, lower_zoom;
+ gint selected_download_method;
+
+ gdouble cur_zoom = vik_viewport_get_zoom(vvp);
+
+ for (default_zoom = 0; default_zoom < sizeof(zoom_vals)/sizeof(gdouble); default_zoom++) {
+ if (cur_zoom == zoom_vals[default_zoom])
+ break;
+ }
+ default_zoom = (default_zoom == sizeof(zoom_vals)/sizeof(gdouble)) ? sizeof(zoom_vals)/sizeof(gdouble) - 1 : default_zoom;
+
+ // Default to only 2 zoom levels below the current one
+ if (default_zoom > 1 )
+ lower_zoom = default_zoom - 2;
+ else
+ lower_zoom = default_zoom;
+
+ // redownload method - needs to align with REDOWNLOAD* macro values
+ gchar *download_list[] = { _("Missing"), _("Bad"), _("New"), _("Reload All"), NULL };
+
+ gchar *title = g_strdup_printf ( ("%s: %s"), vik_maps_layer_get_map_label (vml), _("Download for Zoom Levels") );
+
+ if ( ! maps_dialog_zoom_between ( VIK_GTK_WINDOW_FROM_LAYER(vml),
+ title,
+ zoom_list,
+ lower_zoom,
+ default_zoom,
+ &selected_zoom1,
+ &selected_zoom2,
+ download_list,
+ REDOWNLOAD_NONE, // AKA Missing
+ &selected_download_method ) ) {
+ // Cancelled
+ g_free ( title );
+ return;
+ }
+ g_free ( title );
+
+ // Find out new current positions
+ gdouble min_lat, max_lat, min_lon, max_lon;
+ VikCoord vc_ul, vc_br;
+ vik_viewport_get_min_max_lat_lon ( vvp, &min_lat, &max_lat, &min_lon, &max_lon );
+ struct LatLon ll_ul = { max_lat, min_lon };
+ struct LatLon ll_br = { min_lat, max_lon };
+ vik_coord_load_from_latlon ( &vc_ul, vik_viewport_get_coord_mode (vvp), &ll_ul );
+ vik_coord_load_from_latlon ( &vc_br, vik_viewport_get_coord_mode (vvp), &ll_br );
+
+ // Get Maps Count - call for each zoom level (in reverse)
+ // With REDOWNLOAD_NEW this is a possible maximum
+ // With REDOWNLOAD_NONE this only missing ones - however still has a server lookup per tile
+ gint map_count = 0;
+ gint zz;
+ for ( zz = selected_zoom2; zz >= selected_zoom1; zz-- ) {
+ map_count = map_count + maps_layer_how_many_maps ( vml, vvp, &vc_ul, &vc_br, zoom_vals[zz], selected_download_method );
+ }
+
+ g_debug ("vikmapslayer: download request map count %d for method %d", map_count, selected_download_method);
+
+ // Absolute protection of hammering a map server
+ if ( map_count > REALLY_LARGE_AMOUNT_OF_TILES ) {
+ gchar *str = g_strdup_printf (_("You are not allowed to download more than %d tiles in one go (requested %d)"), REALLY_LARGE_AMOUNT_OF_TILES, map_count);
+ a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(vml), str );
+ g_free (str);
+ return;
+ }
+
+ // Confirm really want to do this
+ if ( map_count > CONFIRM_LARGE_AMOUNT_OF_TILES ) {
+ gchar *str = g_strdup_printf (_("Do you really want to download %d tiles?"), map_count);
+ gboolean ans = a_dialog_yes_or_no ( VIK_GTK_WINDOW_FROM_LAYER(vml), str, NULL );
+ g_free (str);
+ if ( ! ans )
+ return;
+ }
+
+ // Get Maps - call for each zoom level (in reverse)
+ for ( zz = selected_zoom2; zz >= selected_zoom1; zz-- ) {
+ maps_layer_download_section ( vml, vvp, &vc_ul, &vc_br, zoom_vals[zz], selected_download_method );
+ }