Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the user to print the current viewed map #1075

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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