Hi everyone,

I started to use viking recently and I absolutely love it.

I'm also using JOSM heavily when contributing to OSM, and I'm trying to
save on bandwidth by trying to share the imagery cache between them.

I've already submitted the changes to JOSM's tracker, so that it simply
creates a directory hierarchy in the classical on-disk tile format
(Z/X/Y.png). JOSM adds some additional (useless) files into it, but
that's about it.

viking already loads the on-disk tile format, so I could already re-use
the imagery without downloading them twice, but that was inconvenient
when exploring new areas.

With the attached patch I just slightly modify the DIRSTRUCTURE so that
the default cache directory is basically also the same on-disk tile
format: ~/.viking-maps/t[ID]z[z]/(17-zoom)/x/y.png

This way I can just symlink the directories between the two programs,
which is a true boon.

I assume "z" here is actually used by someone? Because I only have 0
myself when browsing through Bing's imagery and mapnik. It would make
sense IMHO to just use the identical function/format between
DIRSTRUCTURE and DIRECTDIRACCESS, and make the "cache" sub-directories
just like any regular tile structure.

"png" is really a fat lie for aerial imagery, but then again both JOSM
and viking load it anyway. Specifying it in DIRSTRUCTURE like for
DIRECTDIRACCESS seemed superfluous, since "png" is hardcoded everywhere.

No user-visible changes, except that the old cache won't be used due to
the name change.

Any chance this or an improved version of this patch could get integrated?

Thanks.

diff -rud viking-1.5.Orig/src/vikmapslayer.c viking-1.5/src/vikmapslayer.c
--- viking-1.5.Orig/src/vikmapslayer.c	2014-03-12 20:51:25.065240587 +0100
+++ viking-1.5/src/vikmapslayer.c	2014-03-12 21:03:56.781208974 +0100
@@ -368,7 +368,7 @@
 /****************************************/
 
 #define DIRECTDIRACCESS "%s%d" G_DIR_SEPARATOR_S "%d" G_DIR_SEPARATOR_S "%d%s"
-#define DIRSTRUCTURE "%st%ds%dz%d" G_DIR_SEPARATOR_S "%d" G_DIR_SEPARATOR_S "%d"
+#define DIRSTRUCTURE "%st%dz%d" G_DIR_SEPARATOR_S "%d" G_DIR_SEPARATOR_S "%d" G_DIR_SEPARATOR_S "%d.png"
 #define MAPS_CACHE_DIR maps_layer_default_dir()
 
 #ifdef WINDOWS
@@ -719,8 +719,8 @@
 		   vml->cache_dir, (17 - mapcoord->scale), mapcoord->x, mapcoord->y, ".png" );
     else
       g_snprintf ( filename_buf, buf_len, DIRSTRUCTURE,
-		   vml->cache_dir, mode,
-		   mapcoord->scale, mapcoord->z, mapcoord->x, mapcoord->y );
+		   vml->cache_dir, mode, mapcoord->z,
+		   (17 - mapcoord->scale), mapcoord->x, mapcoord->y );
 
     if ( g_file_test ( filename_buf, G_FILE_TEST_EXISTS ) == TRUE)
     {
@@ -907,7 +907,7 @@
 	    else
 	      g_snprintf ( path_buf, max_path_len, DIRSTRUCTURE,
 			   vml->cache_dir, mode,
-			   ulm.scale, ulm.z, ulm.x, ulm.y );
+			   ulm.z, (17 - ulm.scale), ulm.x, ulm.y );
             if ( g_file_test ( path_buf, G_FILE_TEST_EXISTS ) == TRUE ) {
 	      GdkGC *black_gc = gtk_widget_get_style(GTK_WIDGET(vvp))->black_gc;
               vik_viewport_draw_line ( vvp, black_gc, xx+tilesize_x_ceil, yy, xx, yy+tilesize_y_ceil );
@@ -1059,7 +1059,7 @@
       gboolean need_download = FALSE;
       g_snprintf ( mdi->filename_buf, mdi->maxlen, DIRSTRUCTURE,
                      mdi->cache_dir, vik_map_source_get_uniq_id(MAPS_LAYER_NTH_TYPE(mdi->maptype)),
-                     mdi->mapcoord.scale, mdi->mapcoord.z, x, y );
+                     mdi->mapcoord.z, (17 - mdi->mapcoord.scale), x, y );
 
       donemaps++;
       int res = a_background_thread_progress ( threaddata, ((gdouble)donemaps) / mdi->mapstoget ); /* this also calls testcancel */
@@ -1148,7 +1148,7 @@
   {
     g_snprintf ( mdi->filename_buf, mdi->maxlen, DIRSTRUCTURE,
                      mdi->cache_dir, vik_map_source_get_uniq_id(MAPS_LAYER_NTH_TYPE(mdi->maptype)),
-                     mdi->mapcoord.scale, mdi->mapcoord.z, mdi->mapcoord.x, mdi->mapcoord.y );
+                     mdi->mapcoord.z, (17 - mdi->mapcoord.scale), mdi->mapcoord.x, mdi->mapcoord.y );
     if ( g_file_test ( mdi->filename_buf, G_FILE_TEST_EXISTS ) == TRUE)
     {
       g_remove ( mdi->filename_buf );
@@ -1204,8 +1204,8 @@
         for ( b = mdi->y0; b <= mdi->yf; b++ )
         {
           g_snprintf ( mdi->filename_buf, mdi->maxlen, DIRSTRUCTURE,
-                       vml->cache_dir, vik_map_source_get_uniq_id(map), ulm.scale,
-                       ulm.z, a, b );
+                       vml->cache_dir, vik_map_source_get_uniq_id(map),
+                       ulm.z, (17 - ulm.scale), a, b );
           if ( g_file_test ( mdi->filename_buf, G_FILE_TEST_EXISTS ) == FALSE )
             mdi->mapstoget++;
         }
@@ -1290,8 +1290,8 @@
   for (i = mdi->x0; i <= mdi->xf; i++) {
     for (j = mdi->y0; j <= mdi->yf; j++) {
       g_snprintf ( mdi->filename_buf, mdi->maxlen, DIRSTRUCTURE,
-                   vml->cache_dir, vik_map_source_get_uniq_id(map), ulm.scale,
-                   ulm.z, i, j );
+                   vml->cache_dir, vik_map_source_get_uniq_id(map),
+                   ulm.z, (17 - ulm.scale), i, j );
       if ( g_file_test ( mdi->filename_buf, G_FILE_TEST_EXISTS ) == FALSE )
             mdi->mapstoget++;
     }
@@ -1375,7 +1375,7 @@
     source = g_strconcat ( "file://", filename, NULL );
   }
   else {
-	filename = g_strdup_printf ( DIRSTRUCTURE, vml->cache_dir, vik_map_source_get_uniq_id(map), ulm.scale, ulm.z, ulm.x, ulm.y );
+	filename = g_strdup_printf ( DIRSTRUCTURE, vml->cache_dir, vik_map_source_get_uniq_id(map), ulm.z, (17 - ulm.scale), ulm.x, ulm.y );
     source = g_strdup_printf ( "http://%s%s";,
                                vik_map_source_default_get_hostname ( VIK_MAP_SOURCE_DEFAULT(map) ),
                                vik_map_source_default_get_uri ( VIK_MAP_SOURCE_DEFAULT(map), &ulm ) );
@@ -1489,7 +1489,7 @@
                 &mapcoord ) ) {
       gchar *filename_buf = g_strdup_printf ( DIRSTRUCTURE,
                      vml->cache_dir, __map_types[vml->maptype].uniq_id,
-                     mapcoord.scale, mapcoord.z, mapcoord.x, mapcoord.y );
+                     mapcoord.z, (17 - mapcoord.scale), mapcoord.x, mapcoord.y );
 
       __map_types[vml->maptype].download ( &mapcoord, filename_buf );
       g_free ( filename_buf );
@@ -1609,8 +1609,8 @@
     for (i = mdi->x0; i <= mdi->xf; i++) {
       for (j = mdi->y0; j <= mdi->yf; j++) {
         g_snprintf ( mdi->filename_buf, mdi->maxlen, DIRSTRUCTURE,
-                     vml->cache_dir, vik_map_source_get_uniq_id(map), ulm.scale,
-                     ulm.z, i, j );
+                     vml->cache_dir, vik_map_source_get_uniq_id(map),
+                     ulm.z, (17 - ulm.scale), i, j );
         if ( mdi->redownload == REDOWNLOAD_NEW ) {
           // Assume the worst - always a new file
           // Absolute value would requires server lookup - but that is too slow

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Viking-devel mailing list
Viking-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/viking-devel
Viking home page: http://viking.sf.net/

Reply via email to