Skip to content

Commit

Permalink
Allow the user to print the current viewed map
Browse files Browse the repository at this point in the history
Refs #88
  • Loading branch information
davidbgk committed May 3, 2023
1 parent 4251a65 commit 0e7561b
Show file tree
Hide file tree
Showing 5 changed files with 827 additions and 1 deletion.
33 changes: 33 additions & 0 deletions umap/static/umap/js/umap.controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,39 @@ L.U.UpdatePermsAction = L.U.BaseAction.extend({

});

L.U.PrintAction = L.U.BaseAction.extend({

options: {
className: 'print-map dark',
tooltip: L._('Print the current view')
},

addHooks: function () {
// dom-to-image creates the image from the map which is then inserted
// and opened within a new tab to be able to print it, we close the
// window in case the body regain the focus (printing cancelled).
domtoimage
.toPng(this.map._container)
.then(function (dataUrl) {
var win = window.open('about:blank', "_new");
win.document.open();
win.document.write(`
<html>
<body
onload="window.print()"
onafterprint="window.close()"
onfocus="window.close()"
>
<img src="${dataUrl}" style="max-width: 100%;"/>
</body>
</html>
`);
win.document.close();
});
}

});

L.U.DrawMarkerAction = L.U.BaseAction.extend({

options: {
Expand Down
Loading

0 comments on commit 0e7561b

Please sign in to comment.