@@ -10,6 +10,7 @@ BEGIN {
10
10
%EXPORT_TAGS = (standard => [@EXPORT_OK ]);
11
11
}
12
12
13
+ use WWW::Curl::Easy;
13
14
use POSIX qw/ pow tan asin/ ;
14
15
use File::Path qw/ make_path/ ;
15
16
use Fcntl qw/ :DEFAULT/ ;
@@ -52,6 +53,12 @@ my %Services = (
52
53
Zoom => 14,
53
54
},
54
55
56
+ maxar => {
57
+ Init => \&MaxarInit,
58
+ UrlGen => \&MaxarUrlGen,
59
+ Proj => \&EPSG3857Proj,
60
+ Zoom => 17,
61
+ },
55
62
);
56
63
57
64
our $Service = undef ;
@@ -166,6 +173,37 @@ KosmoUrlGen($$$)
166
173
$x , $y , $z );
167
174
}
168
175
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 });
169
207
}
170
208
171
209
sub EPSG3857Proj ($$$) {
@@ -202,16 +240,18 @@ sub YandexProj($$$) {
202
240
# Public below
203
241
# ##############################################################################
204
242
205
- sub ProjInit ($) {
243
+ sub
244
+ ProjInit($) {
206
245
my $service = shift ;
207
246
208
247
$service = lc ($service );
209
248
210
249
$Service = $Services {$service };
211
250
212
251
die (" Unknown service\n " ) if not defined $Service ;
213
- }
214
252
253
+ $Service -> {Init }() if defined ($Service -> {Init });
254
+ }
215
255
216
256
sub LatLon2Tile ($$) {
217
257
my ($lat , $lon ) = @_ ;
0 commit comments