Skip to content

Commit f8bd3c7

Browse files
committed
Add Maxar
1 parent e61d9d1 commit f8bd3c7

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

tms/WebMaps.pm

+42-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ BEGIN {
1010
%EXPORT_TAGS = (standard => [@EXPORT_OK]);
1111
}
1212

13+
use WWW::Curl::Easy;
1314
use POSIX qw/pow tan asin/;
1415
use File::Path qw/make_path/;
1516
use Fcntl qw/:DEFAULT/;
@@ -52,6 +53,12 @@ my %Services = (
5253
Zoom => 14,
5354
},
5455

56+
maxar => {
57+
Init => \&MaxarInit,
58+
UrlGen => \&MaxarUrlGen,
59+
Proj => \&EPSG3857Proj,
60+
Zoom => 17,
61+
},
5562
);
5663

5764
our $Service = undef;
@@ -166,6 +173,37 @@ KosmoUrlGen($$$)
166173
$x, $y, $z);
167174
}
168175

176+
sub
177+
MaxarInit()
178+
{
179+
my $curl = WWW::Curl::Easy->new;
180+
181+
$Service->{apikey} = undef;
182+
$curl->setopt(CURLOPT_URL,
183+
'https://josm.openstreetmap.de/mapkey/Maxar-Premium');
184+
$curl->setopt(CURLOPT_USERAGENT, UA);
185+
$curl->setopt(CURLOPT_WRITEDATA, \$Service->{apikey});
186+
187+
my $rv = $curl->perform;
188+
if ($rv != 0) {
189+
die("Maxar API key fetch failed: " . $curl->strerror($rv) .
190+
" " . $curl->errbuf . "\n");
191+
}
192+
if ($curl->getinfo(CURLINFO_HTTP_CODE) != 200) {
193+
die("Maxar API key fetch http code " .
194+
$curl->getinfo(CURLINFO_HTTP_CODE));
195+
}
196+
chomp($Service->{apikey});
197+
}
198+
199+
sub
200+
MaxarUrlGen($$$)
201+
{
202+
my ($x, $y, $z) = @_;
203+
204+
$y = NumTiles($z) - 1 - $y;
205+
return sprintf('https://services.digitalglobe.com/earthservice/tmsaccess/tms/1.0.0/DigitalGlobe:ImageryTileService@EPSG:3857@jpg/%u/%u/%u.jpg?connectId=%s&foo=premium',
206+
$z, $x, $y, $Service->{apikey});
169207
}
170208

171209
sub EPSG3857Proj($$$) {
@@ -202,16 +240,18 @@ sub YandexProj($$$) {
202240
# Public below
203241
###############################################################################
204242

205-
sub ProjInit($) {
243+
sub
244+
ProjInit($) {
206245
my $service = shift;
207246

208247
$service = lc($service);
209248

210249
$Service = $Services{$service};
211250

212251
die("Unknown service\n") if not defined $Service;
213-
}
214252

253+
$Service->{Init}() if defined($Service->{Init});
254+
}
215255

216256
sub LatLon2Tile($$) {
217257
my ($lat, $lon) = @_;

0 commit comments

Comments
 (0)