]> git.street.me.uk Git - andy/viking.git/commitdiff
SF Features#121: Support reading alternative forms of tile image names.
authorRob Norris <rw_norris@hotmail.com>
Thu, 28 Aug 2014 22:17:36 +0000 (23:17 +0100)
committerRob Norris <rw_norris@hotmail.com>
Sat, 13 Sep 2014 08:15:37 +0000 (09:15 +0100)
Ability to specify the file name extension of tiles read from the disk cache.
The property is 'file-extension' in the maps.xml configuration file.

doc/examples/maps.xml
help/C/viking.xml
help/viking.xml
src/vikmapslayer.c
src/vikmapsource.c
src/vikmapsource.h
src/vikmapsourcedefault.c

index 95255a2136cd7edd2aad5cb6bdd6e26be94321eb..3605c4d4a0cfa2b3b9822a69718cd96ceecd23be 100644 (file)
@@ -12,6 +12,7 @@
     <property name="copyright">© OpenStreetMap contributors</property>
     <property name="license">CC-BY-SA</property>
     <property name="license-url">http://www.openstreetmap.org/copyright</property>
+    <property name="file-extension">.png</property>
   </object>
   <!-- The VikTmsMapSource allows to declare any TMS service. -->
   <!-- Note this service is no longer working
index 3101c77af42143ff2de4a0698bf657f6450bb814..f3391efcf001325b0a6ce5a0915c782768a07858 100644 (file)
@@ -2826,6 +2826,17 @@ Accept: */*
                  <para>See <ulink url="http://wiki.openstreetmap.org/wiki/Zoom_levels">Zoom Levels</ulink></para>
               </listitem>
             </varlistentry>
+            <varlistentry>
+              <term>file-extension (optional)</term>
+              <listitem>
+                <para>The file extension of the files on disk. The default is <emphasis>.png</emphasis></para>
+                <para>If the tile source URL ends in something other than .png, then this parameter will need to match it.</para>
+                <para>This can also be useful in reading a tileset from other software which may name tiles in an alternative form,
+                      e.g. for Mobile Atlas creator it names them <emphasis>.png.tile</emphasis></para>
+                <note><para>The file types actually usable are those supported by GDK Pixbuf Library, which includes at least PNG and JPEG.</para></note>
+                <note><para>Remember to include the beginning <emphasis>'.'</emphasis> when specifying this parameter.</para></note>
+              </listitem>
+            </varlistentry>
             <varlistentry>
               <term>switch-xy (optional)</term>
               <listitem><para>Swap the X,Y values around in the URL parametrized ordering.</para></listitem>
index 0e6018a2465fc56840320079c487cc819513835c..bb4a947ed0c846eaf294a1d6cbb05b451cc418bf 100644 (file)
@@ -222,6 +222,17 @@ and docbook-xsl in your Build-Depends control field.
                  <para>See <ulink url="http://wiki.openstreetmap.org/wiki/Zoom_levels">Zoom Levels</ulink></para>
               </listitem>
             </varlistentry>
+            <varlistentry>
+              <term>file-extension (optional)</term>
+              <listitem>
+                <para>The file extension of the files on disk. The default is <emphasis>.png</emphasis></para>
+                <para>If the tile source URL ends in something other than .png, then this parameter will need to match it.</para>
+                <para>This can also be useful in reading a tileset from other software which may name tiles in an alternative form,
+                      e.g. for Mobile Atlas creator it names them <emphasis>.png.tile</emphasis></para>
+                <note><para>The file types actually usable are those supported by GDK Pixbuf Library, which includes at least PNG and JPEG.</para></note>
+                <note><para>Remember to include the beginning <emphasis>'.'</emphasis> when specifying this parameter.</para></note>
+              </listitem>
+            </varlistentry>
             <varlistentry>
               <term>switch-xy (optional)</term>
               <listitem><para>Swap the X,Y values around in the URL parametrized ordering.</para></listitem>
index 355057c5aadd69bb52807629834b3addaa20ed04..ce3a5d708625975952fb443bf9900590e862dcfc 100644 (file)
@@ -990,20 +990,21 @@ static void get_filename ( const gchar *cache_dir,
                            gint x,
                            gint y,
                            gchar *filename_buf,
-                           gint buf_len )
+                           gint buf_len,
+                           const gchar* file_extension )
 {
   switch ( cl ) {
     case VIK_MAPS_CACHE_LAYOUT_OSM:
       if ( name ) {
         if ( g_strcmp0 ( cache_dir, MAPS_CACHE_DIR ) )
           // Cache dir not the default - assume it's been directed somewhere specific
-          g_snprintf ( filename_buf, buf_len, DIRECTDIRACCESS, cache_dir, (17 - scale), x, y, ".png" );
+          g_snprintf ( filename_buf, buf_len, DIRECTDIRACCESS, cache_dir, (17 - scale), x, y, file_extension );
         else
           // Using default cache - so use the map name in the directory path
-          g_snprintf ( filename_buf, buf_len, DIRECTDIRACCESS_WITH_NAME, cache_dir, name, (17 - scale), x, y, ".png" );
+          g_snprintf ( filename_buf, buf_len, DIRECTDIRACCESS_WITH_NAME, cache_dir, name, (17 - scale), x, y, file_extension );
       }
       else
-        g_snprintf ( filename_buf, buf_len, DIRECTDIRACCESS, cache_dir, (17 - scale), x, y, ".png" );
+        g_snprintf ( filename_buf, buf_len, DIRECTDIRACCESS, cache_dir, (17 - scale), x, y, file_extension );
       break;
     default:
       g_snprintf ( filename_buf, buf_len, DIRSTRUCTURE, cache_dir, id, scale, z, x, y );
@@ -1020,9 +1021,10 @@ static GdkPixbuf *get_pixbuf( VikMapsLayer *vml, guint16 id, const gchar* mapnam
                             id, mapcoord->scale, vml->alpha, xshrinkfactor, yshrinkfactor, vml->filename );
 
   if ( ! pixbuf ) {
-    if ( vik_map_source_is_direct_file_access (MAPS_LAYER_NTH_TYPE(vml->maptype)) ) {
+    VikMapSource *map = MAPS_LAYER_NTH_TYPE(vml->maptype);
+    if ( vik_map_source_is_direct_file_access(map) ) {
       // ATM MBTiles must be 'a direct access type'
-      if ( vik_map_source_is_mbtiles (MAPS_LAYER_NTH_TYPE(vml->maptype)) ) {
+      if ( vik_map_source_is_mbtiles(map) ) {
         pixbuf = get_mbtiles_pixbuf ( vml, mapcoord->x, mapcoord->y, (17 - mapcoord->scale) );
         pixbuf = pixbuf_apply_settings ( pixbuf, vml, mapcoord, xshrinkfactor, yshrinkfactor );
         // return now to avoid file tests that aren't appropriate for this map type
@@ -1030,11 +1032,13 @@ static GdkPixbuf *get_pixbuf( VikMapsLayer *vml, guint16 id, const gchar* mapnam
       }
       else
         get_filename ( vml->cache_dir, VIK_MAPS_CACHE_LAYOUT_OSM, id, NULL,
-                       mapcoord->scale, mapcoord->z, mapcoord->x, mapcoord->y, filename_buf, buf_len );
+                       mapcoord->scale, mapcoord->z, mapcoord->x, mapcoord->y, filename_buf, buf_len,
+                       vik_map_source_get_file_extension(map) );
     }
     else
       get_filename ( vml->cache_dir, vml->cache_layout, id, mapname,
-                     mapcoord->scale, mapcoord->z, mapcoord->x, mapcoord->y, filename_buf, buf_len );
+                     mapcoord->scale, mapcoord->z, mapcoord->x, mapcoord->y, filename_buf, buf_len,
+                     vik_map_source_get_file_extension(map) );
 
     if ( g_file_test ( filename_buf, G_FILE_TEST_EXISTS ) == TRUE)
     {
@@ -1220,10 +1224,10 @@ static void maps_layer_draw_section ( VikMapsLayer *vml, VikViewport *vvp, VikCo
           if ( existence_only ) {
             if ( vik_map_source_is_direct_file_access (MAPS_LAYER_NTH_TYPE(vml->maptype)) )
               get_filename ( vml->cache_dir, VIK_MAPS_CACHE_LAYOUT_OSM, id, vik_map_source_get_name(map),
-                             ulm.scale, ulm.z, ulm.x, ulm.y, path_buf, max_path_len );
+                             ulm.scale, ulm.z, ulm.x, ulm.y, path_buf, max_path_len, vik_map_source_get_file_extension(map) );
             else
               get_filename ( vml->cache_dir, vml->cache_layout, id, vik_map_source_get_name(map),
-                             ulm.scale, ulm.z, ulm.x, ulm.y, path_buf, max_path_len );
+                             ulm.scale, ulm.z, ulm.x, ulm.y, path_buf, max_path_len, vik_map_source_get_file_extension(map) );
 
             if ( g_file_test ( path_buf, G_FILE_TEST_EXISTS ) == TRUE ) {
              GdkGC *black_gc = gtk_widget_get_style(GTK_WIDGET(vvp))->black_gc;
@@ -1379,7 +1383,8 @@ static int map_download_thread ( MapDownloadInfo *mdi, gpointer threaddata )
       get_filename ( mdi->cache_dir, mdi->cache_layout,
                      vik_map_source_get_uniq_id(MAPS_LAYER_NTH_TYPE(mdi->maptype)),
                      vik_map_source_get_name(MAPS_LAYER_NTH_TYPE(mdi->maptype)),
-                     mdi->mapcoord.scale, mdi->mapcoord.z, x, y, mdi->filename_buf, mdi->maxlen );
+                     mdi->mapcoord.scale, mdi->mapcoord.z, x, y, mdi->filename_buf, mdi->maxlen,
+                     vik_map_source_get_file_extension(MAPS_LAYER_NTH_TYPE(mdi->maptype)) );
 
       donemaps++;
       int res = a_background_thread_progress ( threaddata, ((gdouble)donemaps) / mdi->mapstoget ); /* this also calls testcancel */
@@ -1488,7 +1493,8 @@ static void mdi_cancel_cleanup ( MapDownloadInfo *mdi )
     get_filename ( mdi->cache_dir, mdi->cache_layout,
                    vik_map_source_get_uniq_id(MAPS_LAYER_NTH_TYPE(mdi->maptype)),
                    vik_map_source_get_name(MAPS_LAYER_NTH_TYPE(mdi->maptype)),
-                   mdi->mapcoord.scale, mdi->mapcoord.z, mdi->mapcoord.x, mdi->mapcoord.y, mdi->filename_buf, mdi->maxlen );
+                   mdi->mapcoord.scale, mdi->mapcoord.z, mdi->mapcoord.x, mdi->mapcoord.y, mdi->filename_buf, mdi->maxlen,
+                   vik_map_source_get_file_extension(MAPS_LAYER_NTH_TYPE(mdi->maptype)) );
     if ( g_file_test ( mdi->filename_buf, G_FILE_TEST_EXISTS ) == TRUE)
     {
       g_remove ( mdi->filename_buf );
@@ -1547,7 +1553,8 @@ static void start_download_thread ( VikMapsLayer *vml, VikViewport *vvp, const V
           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, a, b, mdi->filename_buf, mdi->maxlen );
+                         ulm.scale, ulm.z, a, b, mdi->filename_buf, mdi->maxlen,
+                         vik_map_source_get_file_extension(map) );
           if ( g_file_test ( mdi->filename_buf, G_FILE_TEST_EXISTS ) == FALSE )
             mdi->mapstoget++;
         }
@@ -1635,7 +1642,8 @@ static void maps_layer_download_section ( VikMapsLayer *vml, VikViewport *vvp, V
       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 );
+                     ulm.scale, ulm.z, i, j, mdi->filename_buf, mdi->maxlen,
+                     vik_map_source_get_file_extension(map) );
       if ( g_file_test ( mdi->filename_buf, G_FILE_TEST_EXISTS ) == FALSE )
             mdi->mapstoget++;
     }
@@ -1747,7 +1755,8 @@ static void maps_layer_tile_info ( VikMapsLayer *vml )
       get_filename ( vml->cache_dir, VIK_MAPS_CACHE_LAYOUT_OSM,
                      vik_map_source_get_uniq_id(map),
                      NULL,
-                     ulm.scale, ulm.z, ulm.x, ulm.y, filename, max_path_len );
+                     ulm.scale, ulm.z, ulm.x, ulm.y, filename, max_path_len,
+                     vik_map_source_get_file_extension(map) );
       source = g_strconcat ( "file://", filename, NULL );
     }
   }
@@ -1757,7 +1766,8 @@ static void maps_layer_tile_info ( VikMapsLayer *vml )
     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, ulm.x, ulm.y, filename, max_path_len );
+                   ulm.scale, ulm.z, ulm.x, ulm.y, filename, max_path_len,
+                   vik_map_source_get_file_extension(map) );
     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 ) );
@@ -1984,7 +1994,8 @@ static gint maps_layer_how_many_maps ( VikMapsLayer *vml, VikViewport *vvp, VikC
         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 );
+                       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 requires server lookup - but that is too slow
index 0b2cad22eea94f9f929fcffb1018a730771374cd..ef7d9f7be7fbfa8d296754ec7dbf069a771f2199 100644 (file)
@@ -314,6 +314,28 @@ vik_map_source_get_zoom_max (VikMapSource * self)
        return (*klass->get_zoom_max)(self);
 }
 
+
+/**
+ * vik_map_source_get_file_extension:
+ * @self: the VikMapSource of interest.
+ *
+ * Returns the file extension of files held on disk.
+ *  Typically .png but may be .jpg or whatever the user defines
+ *
+ */
+const gchar *
+vik_map_source_get_file_extension (VikMapSource * self)
+{
+       VikMapSourceClass *klass;
+       g_return_val_if_fail (self != NULL, NULL);
+       g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
+       klass = VIK_MAP_SOURCE_GET_CLASS(self);
+
+       g_return_val_if_fail (klass->get_file_extension != NULL, NULL);
+
+       return (*klass->get_file_extension)(self);
+}
+
 gboolean
 vik_map_source_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
 {
index 7d6c2b2495fdca773664e5fe0fd72ce7c35611fd..c120e2e7cc6f88b358d70b46ac92e11e36edf8d8 100644 (file)
@@ -60,6 +60,7 @@ struct _VikMapSourceClass
        gboolean (* supports_download_only_new) (VikMapSource * self);
        guint8 (* get_zoom_min) (VikMapSource * self);
        guint8 (* get_zoom_max) (VikMapSource * self);
+       const gchar * (* get_file_extension) (VikMapSource * self);
        gboolean (* coord_to_mapcoord) (VikMapSource * self, const VikCoord * src, gdouble xzoom, gdouble yzoom, MapCoord * dest);
        void (* mapcoord_to_center_coord) (VikMapSource * self, MapCoord * src, VikCoord * dest);
        int (* download) (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void * handle);
@@ -90,6 +91,7 @@ gboolean vik_map_source_is_mbtiles (VikMapSource * self);
 gboolean vik_map_source_supports_download_only_new (VikMapSource * self);
 guint8 vik_map_source_get_zoom_min (VikMapSource * self);
 guint8 vik_map_source_get_zoom_max (VikMapSource * self);
+const gchar * vik_map_source_get_file_extension (VikMapSource * self);
 gboolean vik_map_source_coord_to_mapcoord (VikMapSource * self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest );
 void vik_map_source_mapcoord_to_center_coord (VikMapSource * self, MapCoord *src, VikCoord *dest);
 int vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void * handle);
index d08f82a38da0ce83926269d005d16681ced83ddb..3a2579372466d4073662e242ca769fcf5643cedd 100644 (file)
@@ -41,6 +41,7 @@ static const gchar *map_source_get_label (VikMapSource *self);
 static guint16 map_source_get_tilesize_x (VikMapSource *self);
 static guint16 map_source_get_tilesize_y (VikMapSource *self);
 static VikViewportDrawMode map_source_get_drawmode (VikMapSource *self);
+static const gchar *map_source_get_file_extension (VikMapSource *self);
 
 static DownloadResult_t _download ( VikMapSource *self, MapCoord *src, const gchar *dest_fn, void *handle );
 static void * _download_handle_init ( VikMapSource *self );
@@ -61,6 +62,7 @@ struct _VikMapSourceDefaultPrivate
        guint16 tilesize_x;
        guint16 tilesize_y;
        VikViewportDrawMode drawmode;
+       gchar *file_extension;
 };
 
 #define VIK_MAP_SOURCE_DEFAULT_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIK_TYPE_MAP_SOURCE_DEFAULT, VikMapSourceDefaultPrivate))
@@ -79,6 +81,7 @@ enum
   PROP_COPYRIGHT,
   PROP_LICENSE,
   PROP_LICENSE_URL,
+  PROP_FILE_EXTENSION,
 };
 
 G_DEFINE_ABSTRACT_TYPE (VikMapSourceDefault, vik_map_source_default, VIK_TYPE_MAP_SOURCE);
@@ -95,6 +98,7 @@ vik_map_source_default_init (VikMapSourceDefault *object)
   priv->license_url = NULL;
   priv->logo = NULL;
   priv->name = NULL;
+  priv->file_extension = NULL;
 }
 
 static void
@@ -115,6 +119,8 @@ vik_map_source_default_finalize (GObject *object)
   priv->license_url = NULL;
   g_free (priv->name);
   priv->name = NULL;
+  g_free (priv->file_extension);
+  priv->file_extension = NULL;
 
   G_OBJECT_CLASS (vik_map_source_default_parent_class)->finalize (object);
 }
@@ -174,6 +180,11 @@ vik_map_source_default_set_property (GObject      *object,
       priv->license_url = g_strdup(g_value_get_string (value));
       break;
 
+    case PROP_FILE_EXTENSION:
+      g_free (priv->file_extension);
+      priv->file_extension = g_strdup(g_value_get_string(value));
+      break;
+
     default:
       /* We don't have any other property... */
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -228,6 +239,10 @@ vik_map_source_default_get_property (GObject    *object,
       g_value_set_string (value, priv->license_url);
       break;
 
+    case PROP_FILE_EXTENSION:
+      g_value_set_string (value, priv->file_extension);
+      break;
+
     default:
       /* We don't have any other property... */
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -256,6 +271,7 @@ vik_map_source_default_class_init (VikMapSourceDefaultClass *klass)
        parent_class->get_tilesize_x = map_source_get_tilesize_x;
        parent_class->get_tilesize_y = map_source_get_tilesize_y;
        parent_class->get_drawmode =   map_source_get_drawmode;
+       parent_class->get_file_extension = map_source_get_file_extension;
        parent_class->download =                 _download;
        parent_class->download_handle_init =     _download_handle_init;
        parent_class->download_handle_cleanup =  _download_handle_cleanup;
@@ -335,6 +351,13 @@ vik_map_source_default_class_init (VikMapSourceDefaultClass *klass)
                                     G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
        g_object_class_install_property (object_class, PROP_LICENSE_URL, pspec);
 
+       pspec = g_param_spec_string ("file-extension",
+                                    "File Extension",
+                                    "The file extension of tile files on disk",
+                                    ".png" /* default value */,
+                                    G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+       g_object_class_install_property (object_class, PROP_FILE_EXTENSION, pspec);
+
        g_type_class_add_private (klass, sizeof (VikMapSourceDefaultPrivate));
 
        object_class->finalize = vik_map_source_default_finalize;
@@ -455,6 +478,14 @@ _download ( VikMapSource *self, MapCoord *src, const gchar *dest_fn, void *handl
    return res;
 }
 
+static const gchar *
+map_source_get_file_extension (VikMapSource *self)
+{
+    g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT(self), NULL);
+    VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE(self);
+    return priv->file_extension;
+}
+
 static void *
 _download_handle_init ( VikMapSource *self )
 {