npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

leaflet-simple-map-screenshoter

v0.5.0

Published

Leaflet plugin plugin which take screenshot of map

Downloads

11,124

Readme

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 * as L from 'leaflet'
// import script after leaflet
import {SimpleMapScreenshoter} from 'leaflet-simple-map-screenshoter'

new SimpleMapScreenshoter().addTo(this.map)

From cdn

<script src="https://unpkg.com/leaflet"></script>
<script src="https://unpkg.com/leaflet-simple-map-screenshoter"></script>
<script>
L.simpleMapScreenshoter().addTo(map)
</script>

For custom usage

import 'leaflet'
// import script after leaflet
import 'leaflet-simple-map-screenshoter'

let pluginOptions = {
   cropImageByInnerWH: true, // crop blank opacity from image borders
   hidden: false, // hide screen icon
   preventDownload: false, // prevent download on button click
   domtoimageOptions: {}, // see options for dom-to-image
   position: 'topleft', // position of take screen icon
   screenName: 'screen', // string or function
   iconUrl: ICON_SVG_BASE64, // screen btn icon base64 or url
   hideElementsWithSelectors: ['.leaflet-control-container'], // by default hide map controls All els must be child of _map._container
   mimeType: 'image/png', // used if format == image,
   caption: null, // string or function, added caption to bottom of screen
   captionFontSize: 15,
   captionFont: 'Arial',
   captionColor: 'black',
   captionBgColor: 'white',
   captionOffset: 5,
   // callback for manually edit map if have warn: "May be map size very big on that zoom level, we have error"
   // and screenshot not created
   onPixelDataFail: async function({ node, plugin, error, mapPane, domtoimageOptions }) {
       // Solutions:
       // decrease size of map
       // or decrease zoom level
       // or remove elements with big distanses
       // and after that return image in Promise - plugin._getPixelDataOfNormalMap
       return plugin._getPixelDataOfNormalMap(domtoimageOptions)
   }
}

this.simpleMapScreenshoter = L.simpleMapScreenshoter(pluginOptions).addTo(this.map)
let format = 'blob' // 'image' - return base64, 'canvas' - return canvas
let overridedPluginOptions = {
  mimeType: 'image/jpeg'
}
this.simpleMapScreenshoter.takeScreen(format, overridedPluginOptions).then(blob => {
   alert('done')
   // FileSaver.saveAs(blob, 'screen.png')
}).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