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 authored and yohanboniface committed Dec 22, 2023
1 parent 417f1b9 commit 0cba87d
Show file tree
Hide file tree
Showing 5 changed files with 826 additions and 0 deletions.
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 @@ -86,6 +86,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: {
helpMenu: true,
Expand Down
Loading

0 comments on commit 0cba87d

Please sign in to comment.