Created
August 30, 2017 22:13
-
-
Save JonForest/236bee2f44f1e9841adea73f434bec9e to your computer and use it in GitHub Desktop.
Download button that works for Firefox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function setupExportBtn () { | |
| const exportBtn = '<button id="export-btn">Download pdf</button>' | |
| $('div.leaflet-control-layers').append(exportBtn) | |
| // create hidden link for downloading export pdf | |
| const hiddenLink = document.createElement('a') | |
| hiddenLink.setAttribute('download', 'download.pdf') | |
| hiddenLink.style = 'display:none;' | |
| hiddenLink.target = '_blank' | |
| document.body.append(hiddenLink) | |
| $('#export-btn').on('click', (e) => { | |
| e.preventDefault() | |
| const bbox = map.getBounds().toBBoxString() | |
| hiddenLink.setAttribute('href', `/path/to/download.pdf`) | |
| hiddenLink.click() | |
| }) | |
| toggleExportBtn(initialZoom) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment