From 1c52d1397e3e18f678fb45cb1fac5410bc16f836 Mon Sep 17 00:00:00 2001 From: Frederik Ramm Date: Mon, 29 Jun 2020 15:57:07 +0200 Subject: [PATCH] support template URL for TMS backend --- debian/changelog | 4 ++++ etc/renderer/tms/demotms.conf.dist | 4 ++-- lib/Tirex/Backend/TMS.pm | 20 ++++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/debian/changelog b/debian/changelog index f7d7623..2decc00 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,7 @@ +tirex (0.6.3) bionic; urgency=medium + + * modify TMS backend to take template URL parameter + tirex (0.6.2) bionic; urgency=medium * add TMS backend diff --git a/etc/renderer/tms/demotms.conf.dist b/etc/renderer/tms/demotms.conf.dist index 7a76c47..e2b847a 100644 --- a/etc/renderer/tms/demotms.conf.dist +++ b/etc/renderer/tms/demotms.conf.dist @@ -26,10 +26,10 @@ maxz=10 # Backend specific configuration #----------------------------------------------------------------------------- -# the URL prefix for the TMS server, should probably end with a '?' or '&' +# the URL template for the TMS server, must contain {x} {y} {z} # DO NOT USE tile.openstreetmap.de in a production environment, this is # for testing only! -url=https://a.tile.openstreetmap.de/ +url=https://a.tile.openstreetmap.de/{z}/{x}/{y}.png # "slots" is the maximum number of parallel requests that one backend process # will make; note that if you have several backend processes, these will add up diff --git a/lib/Tirex/Backend/TMS.pm b/lib/Tirex/Backend/TMS.pm index f874b25..66b1675 100644 --- a/lib/Tirex/Backend/TMS.pm +++ b/lib/Tirex/Backend/TMS.pm @@ -33,7 +33,8 @@ Config parameters for the map file: =over 8 -=item url url prefix (to be followed by z/x/y.png) +=item url url template (should contain {x}, {y}, {z} which are replaced) +=item slots maximum number of parallel connections per backend process =back @@ -71,17 +72,24 @@ sub create_metatile my $limit = 2 ** $metatile->get_z(); + my $url = $map->{'url'}; + my $z = $metatile->get_z(); + $url =~ s/{z}/$z/g; + for (my $x = 0; $x < $Tirex::METATILE_COLUMNS; $x++) { my $xx = $metatile->get_x() + $x; - next if ($xx >= $limit); + next if ($xx >= $limit); + my $url1 = $url; + $url1 =~ s/{x}/$xx/g; for (my $y = 0; $y < $Tirex::METATILE_ROWS; $y++) { my $yy = $metatile->get_y() + $y; - next if ($yy >= $limit); - my $url = sprintf("%s/%d/%d/%d.png", $map->{'url'}, $metatile->get_z(), $xx, $yy); - ::syslog('debug', 'TMS request: %s', $url) if ($Tirex::DEBUG); - my $request = HTTP::Request->new('GET', $url, [ 'User-Agent' => 'tirex-backend-tms/' . $Tirex::VERSION ]); + next if ($yy >= $limit); + my $url2 = $url1; + $url2 =~ s/{y}/$yy/g; + ::syslog('debug', 'TMS request: %s', $url2) if ($Tirex::DEBUG); + my $request = HTTP::Request->new('GET', $url2, [ 'User-Agent' => 'tirex-backend-tms/' . $Tirex::VERSION ]); my $async_id = $async->add($request); $async_index->{$async_id} = $x*$Tirex::METATILE_ROWS+$y; }