leaflet-simple-map-screenshoter
Leaflet promise based plugin which take screenshot of map.
Used dom-to-image.
Install
npm install leaflet-simple-map-screenshoter --save
Example
Open (see in /examples)
Usage
Add save screenshot button to leaflet control panel
import 'leaflet'
import 'leaflet-simple-map-screenshoter'
L.simpleMapScreenshoter().addTo(this.map)
For custom usage
import 'leaflet'
import 'leaflet-simple-map-screenshoter'
let pluginOptions = {
cropImageByInnerWH: true,
hidden: false,
domtoimageOptions: {},
position: 'topleft',
screenName: 'screen',
iconUrl: ICON_SVG_BASE64,
hideElementsWithSelectors: ['.leaflet-control-container']
mimeType: 'image/png'
caption: null,
captionFontSize: 15,
captionFont: 'Arial',
captionColor: 'black',
captionBgColor: 'white',
captionOffset: 5,
}
this.simpleMapScreenshoter = L.simpleMapScreenshoter(pluginOptions).addTo(this.map)
let format = 'blob'
let overridedPluginOptions = {
mimeType: 'image/jpeg'
}
this.simpleMapScreenshoter.takeScreen(format, overridedPluginOptions).then(blob => {
alert('done')
}).catch(e => {
console.error(e)
})
Events
simpleMapScreenshoter.click - on leaflet control panel take screen btn click
simpleMapScreenshoter.takeScreen - start build screenshot
simpleMapScreenshoter.done - screenshot build ended
simpleMapScreenshoter.error - on error, return Error instance