Skip to content

Commit 74b889e

Browse files
committed
print update
1 parent dc88e15 commit 74b889e

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

js/print.js

+3-14
Original file line numberDiff line numberDiff line change
@@ -297,29 +297,18 @@ function flip(){
297297
changeDimensions();
298298
}
299299

300-
function save_image() {
301-
console.log('hello');
300+
function save_image(format='png') {
302301
$('#save_image_status').html("Generating image..");
303302
leafletImage(map, function(err, canvas) {
304303
// note: webp format is possible
305-
var dataURL = canvas.toDataURL('image/png');
304+
var dataURL = canvas.toDataURL(`image/${format}`);
306305
var link = document.createElement('a');
307-
link.download = 'map.png'; // Set the download filename
306+
link.download = `map.${format}`; // Set the download filename
308307
link.href = dataURL; // Set the data URL as the link href
309308
// Trigger a click event on the link to start the download
310309
document.body.appendChild(link);
311310
link.click();
312311
document.body.removeChild(link);
313312
$('#save_image_status').html("Image saved.");
314-
// var img = document.createElement('img');
315-
// var dimensions = map.getSize();
316-
// img.width = dimensions.x;
317-
// img.height = dimensions.y;
318-
// img.src = canvas.toDataURL();
319-
// document.getElementById('images').innerHTML = '';
320-
// document.getElementById('images').appendChild(img);
321-
// console.log(img.src);
322-
// console.log(canvas);
323-
// console.log('eh?');
324313
});
325314
}

print.html

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>Map Printer</title>
4+
<title>Large Map Printer / Exporter</title>
55
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
77

@@ -84,7 +84,7 @@
8484
<div class="container-fluid no-print mt-5">
8585
<div class="row">
8686
<div class="col-md-4">
87-
<h1>Map Printer</h1>
87+
<h1>Large Map Printer / Exporter</h1>
8888
<div class="card card-body mb-4">
8989
<ul>
9090
<li>Drag-drop a shape file (preferably .geojson format) onto this map to display its border.</li>
@@ -95,12 +95,13 @@ <h1>Map Printer</h1>
9595
</ul>
9696
</div>
9797

98-
<p><button onclick="zoomFit()" class="btn btn-warning">Fit map to shape</button>
99-
&nbsp;&nbsp;
100-
<button onclick="window.print()" class="btn btn-primary">Print</button>
98+
<p>
10199
&nbsp;&nbsp;
102-
<button onclick="save_image()" class="btn btn-success">Save Image</button>
103-
&nbsp;&nbsp;<span id="save_image_status"></span>
100+
<button onclick="save_image('png')" class="btn btn-outline-success">Save Image as PNG</button>
101+
&nbsp;&nbsp;
102+
<button onclick="save_image('webp')" class="btn btn-outline-success">Save Image as WEBP</button>
103+
&nbsp;&nbsp;
104+
<span id="save_image_status"></span>
104105
</p>
105106

106107

@@ -142,6 +143,10 @@ <h3>Print page size</h3>
142143
<p><b>Note:</b> The presets and css scripting for it are approximations and best-effort attempts. <br>
143144
When you go for the print dialogue and choose your page size etc, there will probably be some mis-match.<br>
144145
Please see the print-preview, then come back here and tweak the width and heigth to get it right. </p>
146+
147+
<p><button onclick="zoomFit()" class="btn btn-warning">Fit map to shape</button>
148+
&nbsp;&nbsp;
149+
<button onclick="window.print()" class="btn btn-primary">Print</button></p>
145150
</div>
146151
<div class="col-md-3">
147152
<h3>Shape</h3>

0 commit comments

Comments
 (0)