Skip to content

Commit

Permalink
Allow manual deletion of map file cached tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
rnorris committed Jan 26, 2025
1 parent 6988ebb commit 5da8eb7
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
7 changes: 7 additions & 0 deletions help/C/index.docbook
Original file line number Diff line number Diff line change
Expand Up @@ -3560,6 +3560,13 @@ The possible methods to redownload one or more tiles are:
</varlistentry>
</variablelist>
</para>
<formalpara><title>Delete Map Tiles</title>
<para>
This removes this specific cached tile(s) from disk (and memory).
Hence allowing fine grained control, which can be useful such as in bypassing the normal tile age cache check
(and then induce a download for this tile) to get the latest tile.
</para>
</formalpara>
<formalpara><title>Map Tile Information</title>
<para>
By right clicking on viewport and selecting <guimenu>Show Tile Information</guimenu> you can see the tile properties of this location for the current <xref linkend="Map"/> layer and current zoom level.
Expand Down
64 changes: 64 additions & 0 deletions src/vikmapslayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,69 @@ static void maps_layer_redownload_new ( VikMapsLayer *vml )
start_download_thread ( vml, vml->redownload_vvp, &(vml->redownload_ul), &(vml->redownload_br), REDOWNLOAD_NEW );
}

/**
* Remove the file(s) of the specific map tile(s)
* This must only be called for cached storage map types
*/
static void maps_layer_delete_tiles ( VikMapsLayer *vml )
{
VikMapSource *map = MAPS_LAYER_NTH_TYPE(vml->maptype);

gdouble xzoom = vml->xmapzoom ? vml->xmapzoom : vik_viewport_get_xmpp ( vml->redownload_vvp );
gdouble yzoom = vml->ymapzoom ? vml->ymapzoom : vik_viewport_get_ympp ( vml->redownload_vvp );
MapCoord ulm, brm;

if ( !vik_map_source_coord_to_mapcoord ( map, &(vml->redownload_ul), xzoom, yzoom, &ulm ) )
return;
if ( !vik_map_source_coord_to_mapcoord ( map, &(vml->redownload_br), xzoom, yzoom, &brm ) )
return;

gint x0 = MIN(ulm.x, brm.x);
gint xf = MAX(ulm.x, brm.x);
gint y0 = MIN(ulm.y, brm.y);
gint yf = MAX(ulm.y, brm.y);

guint max_path_len = strlen(vml->cache_dir) + 40;
gchar *filename = g_malloc ( max_path_len * sizeof(char) );

MapCoord mcoord = ulm;

for (gint xx = x0; xx <= xf; xx++) {
mcoord.x = xx;
for (gint yy = y0; yy <= yf; yy++) {
mcoord.y = yy;

if ( is_in_area (map, mcoord) ) {

get_filename ( vml->cache_dir,
vml->cache_layout,
vik_map_source_get_uniq_id(map),
vik_map_source_get_name(map),
ulm.scale, ulm.z, xx, yy, filename, max_path_len,
vik_map_source_get_file_extension(map) );

if ( g_file_test(filename, G_FILE_TEST_EXISTS) ) {
if ( g_remove(filename) )
g_warning ( "%s failed to remove: %s", __FUNCTION__, filename );
}

// Attempt to remove etag as well if there is one
gchar *etagfile = g_strdup_printf ( "%s.etag", filename );
if ( g_file_test(etagfile, G_FILE_TEST_EXISTS) )
(void)g_remove(etagfile);
g_free ( etagfile );

a_mapcache_remove_all_shrinkfactors ( xx, yy, ulm.z,
vik_map_source_get_uniq_id(map),
ulm.scale, vml->filename );
}
}
}
g_free ( filename );

vik_layer_emit_update ( VIK_LAYER(vml), FALSE );
}

/**
* Display a simple dialog with information about this particular map tile
*/
Expand Down Expand Up @@ -2527,6 +2590,7 @@ static VikLayerToolFuncStatus maps_layer_download_release ( VikMapsLayer *vml, G
(void)vu_menu_add_item ( menu, _("Redownload _Bad Map(s)"), GTK_STOCK_ADD, G_CALLBACK(maps_layer_redownload_bad), vml );
(void)vu_menu_add_item ( menu, _("Redownload _New Map(s)"), GTK_STOCK_REDO, G_CALLBACK(maps_layer_redownload_new), vml );
(void)vu_menu_add_item ( menu, _("Redownload _All Map(s)"), GTK_STOCK_REFRESH, G_CALLBACK(maps_layer_redownload_all), vml );
(void)vu_menu_add_item ( menu, _("_Delete Map Tile(s)"), GTK_STOCK_REMOVE, G_CALLBACK(maps_layer_delete_tiles), vml );
}
(void)vu_menu_add_item ( menu, _("_Show Tile Information"), GTK_STOCK_INFO, G_CALLBACK(maps_layer_tile_info), vml );
}
Expand Down

0 comments on commit 5da8eb7

Please sign in to comment.