-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.html
94 lines (81 loc) · 3.6 KB
/
example.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>L.HighlightableLayers Example</title>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"/>
<link rel="stylesheet" href="https://esm.sh/leaflet/dist/leaflet.css" />
<style type="text/css">
html, body { width: 100%; height: 100%; margin: 0; }
#map { width: 100%; height: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script type="importmap">
{
"imports": {
"leaflet": "https://esm.sh/leaflet",
"leaflet-highlightable-layers": "./dist/L.HighlightableLayers.js"
}
}
</script>
<script type="module">
import * as L from 'leaflet';
import { HighlightableCircle, HighlightableCircleMarker, HighlightableRectangle, HighlightablePolygon, HighlightablePolyline } from 'leaflet-highlightable-layers';
var map = L.map('map',{
center: [52.4830, 13.3414],
zoom: 9
});
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution: '© <a href="http://www.openstreetmap.org/copyright" target="_blank">OSM Contributors</a>',
noWrap: true
}).addTo(map);
const layers = [
new HighlightablePolyline([[53.09897, 12.02728], [52.01701, 14.18884]], { weight: 10 }).addTo(map),
// Test empty polyline, setting coordinates later
new HighlightablePolyline([], { color: '#ffffff', weight: 3 }).addTo(map).setLatLngs([[51.96119, 11.79382], [53.16653, 14.04877]]),
new HighlightablePolyline([], { color: '#ffffff', weight: 3 }).setLatLngs([[51.86119, 11.79382], [53.06653, 14.04877]]).addTo(map),
new HighlightablePolygon([[52.32359, 13.92242], [52.11157, 13.28522], [51.87649, 13.98834]]).addTo(map),
new HighlightablePolyline([[52.06262, 12.55737], [51.98995, 14.1394]], {
generateStyles: (options, renderer) => ({
main: { opacity: 0, weight: 30, pane: 'lhl-almost-over' },
line1: { ...options, color: '#0000ff', weight: 30, renderer },
line2: { ...options, color: '#00ff00', weight: 20, renderer },
line3: { ...options, color: '#ff0000', weight: 10, renderer }
})
}).addTo(map),
new HighlightableCircle([52.54463, 11.68121], { radius: 100, color: "#ffff00" }).addTo(map).setRadius(20000),
new HighlightableCircle([52.84463, 11.98121], { radius: 100, color: "#ffff00" }).setRadius(20000).addTo(map),
new HighlightableCircleMarker([53, 13], { radius: 20, color: "#ffff00" }).addTo(map),
new HighlightableRectangle([[52.91056, 14.40308], [52.91057, 14.40309]], { color: "#ffaaaa" }).setBounds([[52.91056, 14.40308], [52.63806, 15.0705]]).addTo(map),
new HighlightableRectangle([[52.91056, 14.40308], [52.91057, 14.40309]], { color: "#ffaaaa" }).addTo(map).setBounds([[52.51056, 14.40308], [52.23806, 15.0705]]),
new HighlightablePolyline([[52.4, 12], [52.4, 14.2]], {
color: "#ffffff",
weight: 7,
dashArray: "0 11"
}).addTo(map),
new HighlightablePolyline([[52.42, 12], [52.42, 14.2]], {
color: "#000000",
weight: 7,
dashArray: "0 11"
}).addTo(map),
];
function setHighlightedLayer(layer) {
for (const l of layers) {
l.setStyle({ opacity: l === layer ? 0.8 : 0.35, raised: l === layer, outlineFill: l === layer });
}
}
for (const layer of layers) {
layer.on('click', (e) => { setTimeout(() => {
setHighlightedLayer(layer);
}, 0); });
}
map.on('click', (e) => {
setHighlightedLayer(null);
});
setHighlightedLayer(null);
window.lhl = { map, layers, setHighlightedLayer, L, HighlightableCircle, HighlightableRectangle, HighlightablePolygon, HighlightablePolyline };
</script>
</body>
</html>