[libshumate] tile-downloader: Use more common URL template format
- From: Corentin Noël <corentinnoel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libshumate] tile-downloader: Use more common URL template format
- Date: Fri, 11 Mar 2022 15:08:10 +0000 (UTC)
commit 61276cdc46e3e046f3b4f0ad28ae88d333466d2c
Author: James Westman <james jwestman net>
Date: Wed Mar 2 23:26:46 2022 -0600
tile-downloader: Use more common URL template format
Change the URL template placeholders from #X#, #Y#, and #Z# to {x}, {y},
and {z}.
This format is used, for example, in Leaflet and the TileJSON
specification.
Fixes #33.
demos/shumate-demo-window.c | 2 +-
meson.build | 2 +-
shumate/shumate-map-source-registry.c | 18 ++++++------
shumate/shumate-tile-downloader.c | 53 ++++++++---------------------------
4 files changed, 23 insertions(+), 52 deletions(-)
---
diff --git a/demos/shumate-demo-window.c b/demos/shumate-demo-window.c
index e259386..1327408 100644
--- a/demos/shumate-demo-window.c
+++ b/demos/shumate-demo-window.c
@@ -117,7 +117,7 @@ shumate_demo_window_init (ShumateDemoWindow *self)
"Vector Tiles",
"© OpenStreetMap contributors", NULL, 0, 5, 512,
SHUMATE_MAP_PROJECTION_MERCATOR,
- "https://jwestman.pages.gitlab.gnome.org/vector-tile-test-data/world_overview/#Z#/#X#/#Y#.pbf",
+ "https://jwestman.pages.gitlab.gnome.org/vector-tile-test-data/world_overview/{z}/{x}/{y}.pbf",
style_json,
&error
);
diff --git a/meson.build b/meson.build
index 3083690..07044d7 100644
--- a/meson.build
+++ b/meson.build
@@ -53,7 +53,7 @@ cc = meson.get_compiler('c')
libm_dep = cc.find_library('m', required: true)
-glib_req = '>= 2.16.0'
+glib_req = '>= 2.68.0'
cairo_req = '>= 1.4'
sqlite_req = '>= 1.12.0'
introspection_req = '>= 0.6.3'
diff --git a/shumate/shumate-map-source-registry.c b/shumate/shumate-map-source-registry.c
index e144004..2f8cbe5 100644
--- a/shumate/shumate-map-source-registry.c
+++ b/shumate/shumate-map-source-registry.c
@@ -172,7 +172,7 @@ shumate_map_source_registry_populate_defaults (ShumateMapSourceRegistry *self)
18,
256,
SHUMATE_MAP_PROJECTION_MERCATOR,
- "https://tile.openstreetmap.org/#Z#/#X#/#Y#.png"
+ "https://tile.openstreetmap.org/{z}/{x}/{y}.png"
)
);
}
@@ -189,7 +189,7 @@ shumate_map_source_registry_populate_defaults (ShumateMapSourceRegistry *self)
18,
256,
SHUMATE_MAP_PROJECTION_MERCATOR,
- "http://tile.opencyclemap.org/cycle/#Z#/#X#/#Y#.png"
+ "http://tile.opencyclemap.org/cycle/{z}/{x}/{y}.png"
)
);
}
@@ -206,7 +206,7 @@ shumate_map_source_registry_populate_defaults (ShumateMapSourceRegistry *self)
18,
256,
SHUMATE_MAP_PROJECTION_MERCATOR,
- "http://tile.xn--pnvkarte-m4a.de/tilegen/#Z#/#X#/#Y#.png"
+ "http://tile.xn--pnvkarte-m4a.de/tilegen/{z}/{x}/{y}.png"
)
);
}
@@ -223,7 +223,7 @@ shumate_map_source_registry_populate_defaults (ShumateMapSourceRegistry *self)
11,
256,
SHUMATE_MAP_PROJECTION_MERCATOR,
- "http://maps-for-free.com/layer/relief/z#Z#/row#Y#/#Z#_#X#-#Y#.jpg"
+ "http://maps-for-free.com/layer/relief/z{z}/row{y}/{z}_{x}-{y}.jpg"
)
);
}
@@ -240,7 +240,7 @@ shumate_map_source_registry_populate_defaults (ShumateMapSourceRegistry *self)
18,
256,
SHUMATE_MAP_PROJECTION_MERCATOR,
- "http://tile.openweathermap.org/map/clouds/#Z#/#X#/#Y#.png"
+ "http://tile.openweathermap.org/map/clouds/{z}/{x}/{y}.png"
)
);
}
@@ -257,7 +257,7 @@ shumate_map_source_registry_populate_defaults (ShumateMapSourceRegistry *self)
18,
256,
SHUMATE_MAP_PROJECTION_MERCATOR,
- "http://tile.openweathermap.org/map/wind/#Z#/#X#/#Y#.png"
+ "http://tile.openweathermap.org/map/wind/{z}/{x}/{y}.png"
)
);
}
@@ -274,7 +274,7 @@ shumate_map_source_registry_populate_defaults (ShumateMapSourceRegistry *self)
18,
256,
SHUMATE_MAP_PROJECTION_MERCATOR,
- "http://tile.openweathermap.org/map/temp/#Z#/#X#/#Y#.png"
+ "http://tile.openweathermap.org/map/temp/{z}/{x}/{y}.png"
)
);
}
@@ -291,7 +291,7 @@ shumate_map_source_registry_populate_defaults (ShumateMapSourceRegistry *self)
18,
256,
SHUMATE_MAP_PROJECTION_MERCATOR,
- "http://tile.openweathermap.org/map/precipitation/#Z#/#X#/#Y#.png"
+ "http://tile.openweathermap.org/map/precipitation/{z}/{x}/{y}.png"
)
);
}
@@ -308,7 +308,7 @@ shumate_map_source_registry_populate_defaults (ShumateMapSourceRegistry *self)
18,
256,
SHUMATE_MAP_PROJECTION_MERCATOR,
- "http://tile.openweathermap.org/map/pressure/#Z#/#X#/#Y#.png"
+ "http://tile.openweathermap.org/map/pressure/{z}/{x}/{y}.png"
)
);
}
diff --git a/shumate/shumate-tile-downloader.c b/shumate/shumate-tile-downloader.c
index 56efc6a..aef673f 100644
--- a/shumate/shumate-tile-downloader.c
+++ b/shumate/shumate-tile-downloader.c
@@ -229,47 +229,18 @@ get_tile_uri (ShumateTileDownloader *self,
int y,
int z)
{
- char **tokens;
- char *token;
- GString *ret = NULL;
- int i = 0;
-
- tokens = g_strsplit (self->url_template, "#", 20);
- token = tokens[i];
- ret = g_string_sized_new (strlen (self->url_template));
-
- while (token != NULL)
- {
- int number = G_MAXINT;
- char value[SIZE];
-
- if (strcmp (token, "X") == 0)
- number = x;
- if (strcmp (token, "Y") == 0)
- number = y;
- if (strcmp (token, "TMSY") == 0){
- int ymax = 1 << z;
- number = ymax - y - 1;
- }
- if (strcmp (token, "Z") == 0)
- number = z;
-
- if (number != G_MAXINT)
- {
- g_snprintf (value, SIZE, "%d", number);
- g_string_append (ret, value);
- }
- else
- g_string_append (ret, token);
-
- token = tokens[++i];
- }
-
- token = ret->str;
- g_strfreev (tokens);
- g_string_free (ret, FALSE);
-
- return token;
+ GString *string = g_string_new (self->url_template);
+ g_autofree char *x_str = g_strdup_printf("%d", x);
+ g_autofree char *y_str = g_strdup_printf("%d", y);
+ g_autofree char *z_str = g_strdup_printf("%d", z);
+ g_autofree char *tmsy_str = g_strdup_printf("%d", (1 << z) - y - 1);
+
+ g_string_replace (string, "{x}", x_str, 0);
+ g_string_replace (string, "{y}", y_str, 0);
+ g_string_replace (string, "{z}", z_str, 0);
+ g_string_replace (string, "{tmsy}", tmsy_str, 0);
+
+ return g_string_free (string, FALSE);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]