# by bliako for perlmonks 21/08/2025 use Geo::Leaflet; use FindBin; use File::Spec; use WWW::Mechanize::Chrome::Webshot; my $lat = 11.1; my $lon = 22.2; my $outbase = 'hack'; my $map = Geo::Leaflet->new( id => "myMap", center => [$lat, $lon], zoom => 3, ); # the tiles are coming from: $map->tileLayer( # navigation vector tiles #url => 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', # satellite images url => 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', options => { maxZoom => 19, maxNativeZoom => 23, #attribution => 'openstreetmap', attribution => 'esri', }, ); $map->polyline( coordinates => [ [9.0, 20.0], [11.3, 23.1], [12.1, 19.4], ], options=>{color=>'red', weight=>'5'} ); my $map_html = $map->html; my $outdir = $FindBin::Bin; my $map_html_outfile = File::Spec->catfile($outdir, $outbase.'_map.html'); my $FH; open($FH, '>', $map_html_outfile) or die "failed to open file for writing html '$map_html_outfile', $!"; print $FH $map->html; close $FH; my $map_pdf_outfile = File::Spec->catfile($outdir, $outbase.'_map.png'); my $shooter = WWW::Mechanize::Chrome::Webshot->new({ 'settle-time' => 10, 'resolution' => '2000x2000', }); my $local_uri = URI->new('file://'.$map_html_outfile); $shooter->shoot({ 'output-filename' => $map_pdf_outfile, 'url' => $local_uri->as_string, 'remove-DOM-elements' => [ {'element-xpathselector' => '//div[id="leaflet-control-container"]'}, ], 'exif' => {'created' => 'by the shooter'}, }); print "$0 : done, map saved to PDF '$map_pdf_outfile'\n";