Kenyo Joel
Kenyo Joel

Reputation: 301

Generate screenshot of map

How can I generate a image of a div, the div contain a map of leaflet (base layers, overlays)?

Screenshot_Leaflet_Div

Upvotes: 5

Views: 8879

Answers (2)

lastlink
lastlink

Reputation: 1725

What I did on a project was run a nodejs rest api that would launch a chromium instance using puppeteer take a screenshot of a map using long lat and then return the image as a base64. It might be more efficient to generate a map image serverside using leaflet or something else rather than taking a screenshot of a browser.

https://github.com/lastlink/re-store/tree/master/webscraper

Upvotes: 0

snkashis
snkashis

Reputation: 2991

Mapbox's leaflet-image plugin will allow you to kick out an image file of your map container clientside.Enabling canvas mode is required, as seen in their instructions. A more involved server-side approach would include the use of Mapfish/Geoserver and a leaflet plugin, which has a lot more flexibility, but also a lot more configuration.

Upvotes: 1

Related Questions