-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathleaflet.printpreview.js
More file actions
77 lines (64 loc) · 2.96 KB
/
Copy pathleaflet.printpreview.js
File metadata and controls
77 lines (64 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function reCenterMap(center) {
'use strict';
map.setView(center, map.getZoom());
setTimeout(function () {map.invalidateSize(true);}, 100);
}
function SwapOrientation() {
'use strict';
var center = map.getCenter();
var swapfile = document.getElementById("printpreview-swapFile");
if($('#pp-ltr-land').prop('disabled')){
$('#pp-ltr-port').attr('disabled','disabled');
$('#pp-ltr-land').removeAttr('disabled');
swapfile.children[0].className = swapfile.children[0].className.replace(/\ fa-rotate-90/g, "");
swapfile.innerHTML = swapfile.innerHTML.replace(/Landscape/g, "Portrait");
}
else {
$('#pp-ltr-port').removeAttr('disabled');
$('#pp-ltr-land').attr('disabled','disabled');
swapfile.children[0].className += " fa-rotate-90";
swapfile.innerHTML = swapfile.innerHTML.replace(/Portrait/g, "Landscape");
}
reCenterMap(center);
}
function cancelPrintPreview() {
'use strict';
var center = map.getCenter();
$('#pp-main').attr('disabled','disabled');
$('#pp-ltr-land').attr('disabled','disabled');
$('#pp-ltr-port').attr('disabled','disabled');
$('#map').unwrap().unwrap();
$('.leaflet-control-printpreview-bar').remove();
$('#map').removeClass('previewmap');
reCenterMap(center);
}
L.Control.PrintPreview = L.Control.extend({
options: {
title: 'Print preview',
position: 'topleft'
},
onAdd: function () {
'use strict';
//create button and setup click listner
var container = L.DomUtil.create('div', 'leaflet-bar leaflet-control');
this.link = L.DomUtil.create('a', 'leaflet-control-PrintPreview-button leaflet-bar-part', container);
L.DomUtil.create('i', 'fa fa-print fa-lg', this.link);
this.link.title = this.options.title;
L.DomEvent.addListener(this.link, 'click', this.PrintPreview, this.options);
return container;
},
PrintPreview: function () {
'use strict';
var center = map.getCenter();
//add print preview elements
$('#map').addClass('previewmap');
$('#map').wrap('<div class="book"><div class="page"></div></div>');
$('#map').before('<div class="leaflet-control-printpreview-bar"><a class="leaflet-control-printpreview-btn" href="#" onclick="window.print();"><i class="fa fa-print fa-lg" aria-hidden="true"></i> Print</a><a id="printpreview-swapFile" class="leaflet-control-printpreview-btn" href="#" onclick="SwapOrientation();"><i class="fa fa-file-o fa-lg fa-rotate-90" aria-hidden="true"></i> Landscape</a><a class="leaflet-control-printpreview-btn" href="#" onclick="cancelPrintPreview();"><i class="fa fa-times-circle" aria-hidden="true"></i> Cancel Preview</a></div>');
$('#pp-main').removeAttr('disabled');
$('#pp-ltr-port').removeAttr('disabled');
reCenterMap(center);
}
});
L.PrintPreview = function (options) {
return new L.Control.PrintPreview(options);
};