Skip to content

Commit

Permalink
fix example img download in chrome/safari
Browse files Browse the repository at this point in the history
  • Loading branch information
warm-coolguy committed Feb 11, 2025
1 parent 76f6d23 commit 04ad79a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/clients/diplan/example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h2>Informationen aus Kartenklient</h2>
</tr>
<tr>
<td><code>plugin/export/exportedMap</code></td>
<td><img onclick="window.open(this.src, '_blank');" id="subscribed-export" /></td>
<td><a id="subscribed-export-a" download="polar_screenshot.png" href=""><img id="subscribed-export-img" /></a></td>
<td>Screenshot des aktuellen Kartenausschnitts. Produzierbar durch Klick auf den unteren linken "Export"-Button.</td>
</tr>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion packages/clients/diplan/example/prod-example.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h2>Informationen aus Kartenklient</h2>
</tr>
<tr>
<td><code>plugin/export/exportedMap</code></td>
<td><img onclick="window.open(this.src, '_blank');" id="subscribed-export" /></td>
<td><a id="subscribed-export-a" download="polar_screenshot.png" href=""><img id="subscribed-export-img" /></a></td>
<td>Screenshot des aktuellen Kartenausschnitts. Produzierbar durch Klick auf den unteren linken "Export"-Button.</td>
</tr>
<tr>
Expand Down
17 changes: 13 additions & 4 deletions packages/clients/diplan/example/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export default (client, layerConf, config) => {

const htmlZoom = document.getElementById('subscribed-zoom')
const htmlGfi = document.getElementById('subscribed-gfi')
const htmlExport = document.getElementById('subscribed-export')
const htmlExportA = document.getElementById('subscribed-export-a')
const htmlExportImg = document.getElementById('subscribed-export-img')

mapInstance.subscribe(
'plugin/zoom/zoomLevel',
Expand All @@ -52,9 +53,17 @@ export default (client, layerConf, config) => {
'plugin/gfi/featureInformation',
(v) => (htmlGfi.innerHTML = JSON.stringify(v, null, 2))
)
mapInstance.subscribe('plugin/export/exportedMap', (screenshot) =>
htmlExport.setAttribute('src', screenshot)
)
mapInstance.subscribe('plugin/export/exportedMap', (screenshot) => {
htmlExportImg.setAttribute('src', screenshot)
if (navigator.userAgent.toLowerCase().includes('firefox')) {
htmlExportImg.onclick = function () {
window.open(this.src, '_blank')
}
htmlExportA.onclick = () => false
} else {
htmlExportA.setAttribute('href', screenshot)
}
})

window.mapInstance = mapInstance
})
Expand Down

0 comments on commit 04ad79a

Please sign in to comment.