-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.html
78 lines (68 loc) · 2.97 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
<!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": "https://esm.sh/*leaflet-highlightable-layers",
"leaflet-draggable-lines": "./dist/L.DraggableLines.js"
}
}
</script>
<script type="module">
import * as L from 'leaflet';
import { HighlightableCircle, HighlightableCircleMarker, HighlightablePolygon, HighlightablePolyline, HighlightableRectangle } from 'leaflet-highlightable-layers';
import DraggableLines from 'leaflet-draggable-lines';
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);
new HighlightablePolyline([
[[53.09897, 12.02728], [52.01701, 14.18884]],
[[52.93871, 11.92566], [52.73629, 12.57935]]
], { color: '#0000ff', weight: 10 }).addTo(map);
new HighlightableCircle([52.34463, 11.68121], { radius: 20000, color: "#ffff00" }).addTo(map);
new HighlightableCircleMarker([53, 13], { radius: 20, color: "#ffff00" }).addTo(map);
new HighlightableRectangle([[52.91056, 14.40308], [52.63806, 15.0705]], { color: "#ffaaaa" }).addTo(map);
const draggable = new DraggableLines(map);
draggable.enable();
setTimeout(() => {
new L.Polyline([[51.96119, 11.79382], [53.16653, 14.04877]], { color: '#ff0000', weight: 50 }).addTo(map);
new HighlightablePolygon([
[[52.32359, 13.92242], [52.11157, 13.28522], [51.87649, 13.98834]],
[[52.13012, 13.73085], [52.09005, 13.73257], [52.11831, 13.77617]]
], { weight: 10 }).addTo(map);
}, 100);
const routeLayer = new HighlightablePolyline([], { draggableLinesRoutePoints: [[52.61139, 11.86523], [52.50285, 14.13666]] }).addTo(map);
async function calculateRoute() {
const route = await fetch(`https://router.project-osrm.org/route/v1/driving/${routeLayer.getDraggableLinesRoutePoints().map((p) => `${p.lng},${p.lat}`).join(';')}?geometries=geojson`).then((res) => res.json());
routeLayer.setLatLngs(route.routes[0].geometry.coordinates.map((p) => [p[1], p[0]]));
}
calculateRoute();
draggable.on('dragend remove insert', (e) => {
if (e.layer === routeLayer) {
calculateRoute();
}
});
draggable.on("dragstart dragend remove insert dragmouseover dragmouseout tempmouseover tempmouseout plusmouseover plusmouseout", (e) => {
console.log(e.type, e.idx, e);
});
</script>
</body>
</html>