Skip to content

Commit 0e7561b

Browse files
committed
Allow the user to print the current viewed map
Refs #88
1 parent 4251a65 commit 0e7561b

File tree

5 files changed

+827
-1
lines changed

5 files changed

+827
-1
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,39 @@ L.U.UpdatePermsAction = L.U.BaseAction.extend({
9393

9494
});
9595

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

98131
options: {

0 commit comments

Comments
 (0)