+static void maps_layer_download_missing_onscreen_maps ( menu_array_values values )
+{
+ download_onscreen_maps( values, REDOWNLOAD_NONE);
+}
+
+static void maps_layer_download_new_onscreen_maps ( menu_array_values values )
+{
+ download_onscreen_maps( values, REDOWNLOAD_NEW);
+}
+
+static void maps_layer_redownload_all_onscreen_maps ( menu_array_values values )
+{
+ download_onscreen_maps( values, REDOWNLOAD_ALL);
+}
+
+static void maps_layer_about ( gpointer vml_vvp[2] )
+{
+ VikMapsLayer *vml = vml_vvp[0];
+ VikMapSource *map = MAPS_LAYER_NTH_TYPE(vml->maptype);
+
+ if ( vik_map_source_get_license (map) )
+ maps_show_license ( VIK_GTK_WINDOW_FROM_LAYER(vml), map );
+ else
+ a_dialog_info_msg ( VIK_GTK_WINDOW_FROM_LAYER(vml),
+ vik_map_source_get_label (map) );
+}
+
+/**
+ * maps_layer_how_many_maps:
+ * Copied from maps_layer_download_section but without the actual download and this returns a value
+ */
+static gint maps_layer_how_many_maps ( VikMapsLayer *vml, VikViewport *vvp, VikCoord *ul, VikCoord *br, gdouble zoom, gint redownload )
+{
+ MapCoord ulm, brm;
+ VikMapSource *map = MAPS_LAYER_NTH_TYPE(vml->maptype);
+
+ if ( vik_map_source_is_direct_file_access ( map ) )
+ return 0;
+
+ if (!vik_map_source_coord_to_mapcoord(map, ul, zoom, zoom, &ulm)
+ || !vik_map_source_coord_to_mapcoord(map, br, zoom, zoom, &brm)) {
+ g_warning("%s() coord_to_mapcoord() failed", __PRETTY_FUNCTION__);
+ return 0;
+ }
+
+ MapDownloadInfo *mdi = g_malloc(sizeof(MapDownloadInfo));
+ gint i, j;
+
+ mdi->vml = vml;
+ mdi->vvp = vvp;
+ mdi->map_layer_alive = TRUE;
+ mdi->mutex = vik_mutex_new();
+ mdi->refresh_display = FALSE;
+
+ mdi->cache_dir = g_strdup ( vml->cache_dir );
+ mdi->maxlen = strlen ( vml->cache_dir ) + 40;
+ mdi->filename_buf = g_malloc ( mdi->maxlen * sizeof(gchar) );
+ mdi->maptype = vml->maptype;
+ mdi->cache_layout = vml->cache_layout;
+
+ mdi->mapcoord = ulm;
+ mdi->redownload = redownload;
+
+ mdi->x0 = MIN(ulm.x, brm.x);
+ mdi->xf = MAX(ulm.x, brm.x);
+ mdi->y0 = MIN(ulm.y, brm.y);
+ mdi->yf = MAX(ulm.y, brm.y);
+
+ mdi->mapstoget = 0;
+
+ if ( mdi->redownload == REDOWNLOAD_ALL ) {
+ mdi->mapstoget = (mdi->xf - mdi->x0 + 1) * (mdi->yf - mdi->y0 + 1);
+ }
+ else {
+ /* calculate how many we need */
+ MapCoord mcoord = mdi->mapcoord;
+ for (i = mdi->x0; i <= mdi->xf; i++) {
+ mcoord.x = i;
+ for (j = mdi->y0; j <= mdi->yf; j++) {
+ mcoord.y = j;
+ // Only count tiles from supported areas
+ if ( is_in_area ( map, mcoord ) ) {
+ get_filename ( mdi->cache_dir, mdi->cache_layout,
+ vik_map_source_get_uniq_id(map),
+ vik_map_source_get_name(map),
+ ulm.scale, ulm.z, i, j, mdi->filename_buf, mdi->maxlen,
+ vik_map_source_get_file_extension(map) );
+ if ( mdi->redownload == REDOWNLOAD_NEW ) {
+ // Assume the worst - always a new file
+ // Absolute value would require a server lookup - but that is too slow
+ mdi->mapstoget++;
+ }
+ else {
+ if ( g_file_test ( mdi->filename_buf, G_FILE_TEST_EXISTS ) == FALSE ) {
+ // Missing
+ mdi->mapstoget++;
+ }
+ else {
+ if ( mdi->redownload == REDOWNLOAD_BAD ) {
+ /* see if this one is bad or what */
+ GError *gx = NULL;
+ GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file ( mdi->filename_buf, &gx );
+ if (gx || (!pixbuf)) {
+ mdi->mapstoget++;
+ }
+ break;
+ // Other download cases already considered or just ignored
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ gint rv = mdi->mapstoget;
+
+ mdi_free ( mdi );
+
+ return rv;
+}
+
+/**
+ * maps_dialog_zoom_between:
+ * This dialog is specific to the map layer, so it's here rather than in dialog.c
+ */
+gboolean maps_dialog_zoom_between ( GtkWindow *parent,
+ gchar *title,
+ gchar *zoom_list[],
+ gint default_zoom1,
+ gint default_zoom2,
+ gint *selected_zoom1,
+ gint *selected_zoom2,
+ gchar *download_list[],
+ gint default_download,
+ gint *selected_download )