A simple leaflet plugin which adds an icon to print the map. Compatible with both Leaflet v1+ and 0.7.
Check out the demo.
You can either download this repo directly or install via NPM.
npm install leaflet-easyprint
Step 1. Include the required js files in your document.
<script src="dist/leaflet.easyPrint.js"></script>
Step 2. Add the following line of code to your map script
L.easyPrint().addTo(map)
Step 3. You can pass a number of options to the plugin to control various settings.
Option | Type | Default | Description |
---|---|---|---|
title | string | 'Print map' | Sets the text which appears as the tooltip of the print button |
position | Leaflet control position | 'topleft' | Position the print button |
elementsToHide | string | none | Enables you to pass through a string of html elements to hide when the user prints the page |
Here's an example of passing through some options.
L.easyPrint({
title: 'My awesome print button',
position: 'bottomright',
elementsToHide: 'p, h2'
}).addTo(map);
Huge hats off go to mourner and all the contributors to the leaflet.js project, it's an amazing piece of open source software!
And finally thanks to IcoMoon for the print icon.