-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
index.html
269 lines (233 loc) · 8.1 KB
/
index.html
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<!DOCTYPE html>
<html>
<head>
<title>Leaflet browser print plugin with custom print Layer and content</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/leaflet@latest/dist/leaflet.css"/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@geoman-io/leaflet-geoman-free@latest/dist/leaflet-geoman.css">
<link rel="stylesheet" href="https://leaflet.github.io/Leaflet.markercluster/dist/MarkerCluster.css"/>
<link rel="stylesheet" href="https://leaflet.github.io/Leaflet.markercluster/dist/MarkerCluster.Default.css"/>
<style>
html, body {
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
}
#map {
width: 80%;
margin: auto;
height: 70%;
}
</style>
</head>
<body>
<h1 class="title" leaflet-browser-print-content>Leaflet Browser print TITLE</h1>
<h3 class="sub-content" leaflet-browser-print-content>Leaflet browser print plugin for map printing with additional
controls and content</h3>
<div id="map"></div>
<table leaflet-browser-print-pages>
<thead>
<tr>
<th>Option</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>title</td>
<td>String</td>
<td>'Print map'</td>
<td>Sets the text which appears as the tooltip of the print button</td>
</tr>
<tr>
<td>position</td>
<td><a href="http://leafletjs.com/reference-0.7.7.html#control-position" rel="nofollow">Leaflet control position</a>
</td>
<td>'topleft'</td>
<td>Position the print button</td>
</tr>
<tr>
<td>printModes</td>
<td>Array</td>
<td>["Portrait", "Landscape", "Auto", "Custom"]</td>
<td>Collection of page print actions</td>
</tr>
<tr>
<td>printModesNames</td>
<td>Object</td>
<td>{ Portrait: "Portrait", Landscape: "Landscape", Auto:"Auto", Custom:"Custom" }</td>
<td>Customize each print mode name</td>
</tr>
<tr>
<td>printLayer</td>
<td><a href="http://leafletjs.com/reference-0.7.7.html#tilelayer" rel="nofollow">Leaflet tile layer</a></td>
<td>null</td>
<td>A tiles layer to show instead of all current active tiles layers</td>
</tr>
<tr>
<td>closePopupsOnPrint</td>
<td>Boolean</td>
<td>true</td>
<td>Indicates if we need to force popup closing for printed map</td>
</tr>
<tr>
<td>contentSelector</td>
<td>String</td>
<td>"[leaflet-browser-print-content]"</td>
<td>Content selector for printed map, will select and dynamically inject content on printed maps. For full
functionality please check "Printing additional content section"
</td>
</tr>
</tbody>
</table>
<script src="https://unpkg.com/leaflet@latest/dist/leaflet.js"></script>
<script src="https://leaflet.github.io/Leaflet.markercluster/dist/leaflet.markercluster-src.js"></script>
<script src="dist/leaflet.browser.print.js"></script>
<script src="https://leaflet.github.io/Leaflet.markercluster/example/realworld.388.js">
</script>
<script src="https://cdn.jsdelivr.net/npm/@geoman-io/leaflet-geoman-free@latest/dist/leaflet-geoman.min.js"></script>
<script>
var canvasRenderer = L.canvas();
//Layers
var cities = L.markerClusterGroup();
var arrayOfPoints = [[39.61, -105.02], [39.73, -104.8], [39.77, -105.23]];
L.marker(arrayOfPoints[0]).bindPopup('This is Littleton, CO.').addTo(cities);
L.marker(arrayOfPoints[1]).bindPopup('This is Aurora, CO.').addTo(cities);
L.marker(arrayOfPoints[2]).bindPopup('This is Golden, CO.').addTo(cities);
var p = L.polygon(arrayOfPoints, {color: 'yellow'}).bindTooltip("polygon").bindPopup('This is Polygon, CO.').addTo(cities);
var base = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
});
var wms = L.tileLayer.wms('https://ahocevar.com/geoserver/wms', {
layers: 'topp:states',
CQL_FILTER: 'PERSONS > 2000000',
styles: '',
format: 'image/png',
transparent: true,
});
var map = L.map('map', {
center: [39.73, -104.99],
zoom: 10,
layers: [base, cities]
});
var baseLayers = {
"Origin": base,
"WMS": wms
};
var overlays = {
"Cities": cities
};
L.control.layers(baseLayers, overlays).addTo(map);
L.control.scale({position: 'topleft'}).addTo(map);
map.pm.addControls({
position: 'bottomright',
editControls: false
});
var drawnItems = new L.FeatureGroup().addTo(map);
map.on("pm:create", function (e) {
var type = e.shape,
layer = e.layer;
if (type === 'Marker') {
layer.bindPopup('A popup!');
}
drawnItems.addLayer(layer);
});
map.createPane("new-pane");
var l = L.layerGroup().addTo(map);
var green = L.circle([39.73, -104.99], 5000, {
color: 'green',
fillColor: 'darkgreen',
fillOpacity: 0.8,
pane: "new-pane",
renderer: canvasRenderer
}).addTo(l);
var customActionToPrint = function (context, mode) {
return function () {
window.alert("We are printing the MAP. Let's do Custom print here!");
context._printCustom(mode);
}
};
L.control.browserPrint({
printLayer: L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.{ext}', {
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> — Map data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
subdomains: 'abcd',
minZoom: 1,
maxZoom: 16,
ext: 'png'
}),
closePopupsOnPrint: false,
printModes: [
L.BrowserPrint.Mode.Landscape("Tabloid",{title: "Tabloid VIEW"}),
new L.BrowserPrint.Mode("Alert",{title:"User specified print action",pageSize: "A6", action: customActionToPrint, invalidateBounds: false}),
L.BrowserPrint.Mode.Landscape(),
"Portrait",
L.BrowserPrint.Mode.Auto("B4",{title: "Auto"}),
L.BrowserPrint.Mode.Custom("B5",{title:"Select area"})
]
}).addTo(map);
L.BrowserPrint.Utils.registerLayer(L.TileLayer.WMS, 'L.TileLayer.WMS', function (layer) {
console.info("Printing WMS layer.");
return L.tileLayer.wms(layer._url, layer.options);
});
L.popup({minWidth: 500}).setLatLng(L.latLng(39.73, -104.99)).setContent("Leaflet browser print plugin with custom print Layer and content").openOn(map);
var markers = L.markerClusterGroup();
for (var i = 0; i < addressPoints.length; i++) {
var a = addressPoints[i];
var title = a[2];
var marker = L.marker(new L.LatLng(a[0], a[1]), {title: title});
marker.bindPopup(title);
markers.addLayer(marker);
}
map.addLayer(markers);
// We are not cloning markercluster to preserve original clasterization behavior and prevent OutOfMemory problems
L.BrowserPrint.Utils.registerLayer(L.MarkerClusterGroup, 'L.MarkerClusterGroup', function (layer, utils) {
return layer;
});
// On print end we invalidate markercluster to update markers;
map.on(L.BrowserPrint.Event.PrintEnd, function (e) {
map.removeLayer(markers);
map.addLayer(markers);
});
</script>
<style>
.grid-print-container {
grid-template: auto 1fr auto / 1fr;
background-color: orange;
}
.grid-map-print {
grid-row: 2;
}
.grid-print-container > .title,
.grid-print-container > .sub-content {
color: white;
}
.title {
grid-row: 1;
justify-self: center;
text-align: center;
color: grey;
box-sizing: border-box;
margin-top: 0;
}
.sub-content {
grid-row: 5;
padding-left: 10px;
text-align: center;
color: grey;
box-sizing: border-box;
}
</style>
<style>
[leaflet-browser-print-pages] {
display: none;
}
.pages-print-container [leaflet-browser-print-pages] {
display: block;
}
</style>
</body>
</html>