├── dist ├── print.png ├── easyPrint.css └── leaflet.easyPrint.js ├── LICENSE ├── README.md └── index.html /dist/print.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kyleladd/leaflet-easyPrint/gh-pages/dist/print.png -------------------------------------------------------------------------------- /dist/easyPrint.css: -------------------------------------------------------------------------------- 1 | .leaflet-control-easyPrint a { 2 | background:#fff url(print.png) no-repeat 5px; 3 | background-size:16px 16px; 4 | display: block; 5 | } 6 | 7 | ._epHidden{display:none!important;} 8 | 9 | 10 | @media print { 11 | html {padding: 0px!important;} 12 | .leaflet-control-easyPrint-button{display: none!important;} 13 | } 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Rowan Winsemius 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /dist/leaflet.easyPrint.js: -------------------------------------------------------------------------------- 1 | L.Control.EasyPrint = L.Control.extend({ 2 | options: { 3 | title: 'Print map', 4 | position: 'topleft' 5 | }, 6 | 7 | onAdd: function () { 8 | var container = L.DomUtil.create('div', 'leaflet-control-easyPrint leaflet-bar leaflet-control'); 9 | 10 | this.link = L.DomUtil.create('a', 'leaflet-control-easyPrint-button leaflet-bar-part', container); 11 | this.link.id = "leafletEasyPrint"; 12 | this.link.title = this.options.title; 13 | 14 | L.DomEvent.addListener(this.link, 'click', printPage, this.options); 15 | 16 | return container; 17 | } 18 | 19 | }); 20 | 21 | L.easyPrint = function(options) { 22 | return new L.Control.EasyPrint(options); 23 | }; 24 | 25 | function printPage(){ 26 | 27 | if (this.elementsToHide){ 28 | var htmlElementsToHide = document.querySelectorAll(this.elementsToHide); 29 | 30 | for (var i = 0; i < htmlElementsToHide.length; i++) { 31 | htmlElementsToHide[i].className = htmlElementsToHide[i].className + ' _epHidden'; 32 | } 33 | } 34 | window.print(); 35 | 36 | if (this.elementsToHide){ 37 | var htmlElementsToHide = document.querySelectorAll(this.elementsToHide); 38 | 39 | for (var i = 0; i < htmlElementsToHide.length; i++) { 40 | htmlElementsToHide[i].className = htmlElementsToHide[i].className.replace(' _epHidden',''); 41 | } 42 | } 43 | 44 | 45 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## leaflet-easyPrint 2 | 3 | A simple [leaflet](http://www.leafletjs.com) plugin which adds an icon to print the map. 4 | 5 | Check out the [demo](http://rowanwins.github.com/leaflet-easyPrint/). 6 | 7 | ### Usage 8 | **Step 1.** Include the required js and css files in your document. 9 | 10 | ```html 11 | 12 | 13 | ``` 14 | 15 | **Step 2.** Add the following line of code to your map script 16 | 17 | ``` js 18 | L.easyPrint().addTo(map) 19 | ``` 20 | 21 | **Step 3.** 22 | You can pass a number of options to the plugin to control various settings. 23 | 24 | | Option | Type | Default | Description | 25 | | ------------- |--------------|--------------|---------------| 26 | | title | string | 'Print map' | Sets the text which appears as the tooltip of the print button | 27 | | position | [Leaflet control position](http://leafletjs.com/reference.html#control-positions) | 'topleft' | Position the print button | 28 | | elementsToHide | string | none | Enables you to pass through a string of html elements to hide when the user prints the page | 29 | 30 | Here's an example of passing through some options. 31 | ``` js 32 | L.easyPrint({ 33 | title: 'My awesome print button', 34 | position: 'bottomright', 35 | elementsToHide: 'p, h2' 36 | }).addTo(map); 37 | ``` 38 | 39 | ### Acknowledgements 40 | Huge hats off go to [mourner](https://github.com/mourner) and all the [contributors](https://github.com/Leaflet/Leaflet/graphs/contributors) to the leaflet.js project, it's an amazing piece of open source software! 41 | 42 | And finally thanks to [IcoMoon](http://icomoon.io/) for the print icon. -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 |All this text will be hidden when I print my map.
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 72 |So will this boring sentence.
73 |