Skip to content

Commit 0cba87d

Browse files
davidbgkyohanboniface
authored andcommitted
Allow the user to print the current viewed map
Refs #88
1 parent 417f1b9 commit 0cba87d

File tree

5 files changed

+826
-0
lines changed

5 files changed

+826
-0
lines changed

umap/static/umap/js/umap.controls.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,39 @@ L.U.UpdatePermsAction = L.U.BaseAction.extend({
8686
},
8787
})
8888

89+
L.U.PrintAction = L.U.BaseAction.extend({
90+
91+
options: {
92+
className: 'print-map dark',
93+
tooltip: L._('Print the current view')
94+
},
95+
96+
addHooks: function () {
97+
// dom-to-image creates the image from the map which is then inserted
98+
// and opened within a new tab to be able to print it, we close the
99+
// window in case the body regain the focus (printing cancelled).
100+
domtoimage
101+
.toPng(this.map._container)
102+
.then(function (dataUrl) {
103+
var win = window.open('about:blank', "_new");
104+
win.document.open();
105+
win.document.write(`
106+
<html>
107+
<body
108+
onload="window.print()"
109+
onafterprint="window.close()"
110+
onfocus="window.close()"
111+
>
112+
<img src="${dataUrl}" style="max-width: 100%;"/>
113+
</body>
114+
</html>
115+
`);
116+
win.document.close();
117+
});
118+
}
119+
120+
});
121+
89122
L.U.DrawMarkerAction = L.U.BaseAction.extend({
90123
options: {
91124
helpMenu: true,

0 commit comments

Comments
 (0)