Skip to content

Instantly share code, notes, and snippets.

@JonForest
Created August 30, 2017 22:13
Show Gist options
  • Select an option

  • Save JonForest/236bee2f44f1e9841adea73f434bec9e to your computer and use it in GitHub Desktop.

Select an option

Save JonForest/236bee2f44f1e9841adea73f434bec9e to your computer and use it in GitHub Desktop.
Download button that works for Firefox
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