forked from IvanSanchez/Leaflet.Polyline.SnakeAnim
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdemo-not-flat.html
97 lines (75 loc) · 2.57 KB
/
demo-not-flat.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Leaflet debug page</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
crossorigin=""></script>
<script src="L.Polyline.SnakeAnim.js"></script>
</head>
<body>
<div id="map" style="width: 800px; height: 600px; border: 1px solid #ccc"></div>
<div>
<p></p>
<button onclick='snake()'>SNAKE! IT'S A SNAKE!</button><button onclick='snakeOut()'>SNAKE! GO OUT!</button>
</div>
<div>
<p><label for="checkFollowHead">Follow head: </label><input type="checkbox" id="checkFollowHead" onclick="snakeFollow()"></p>
<button onclick='snakeLaunch()'>LAUNCH A SNAKE!</button><button onclick='snakeReset()'>RESET THE SNAKE!</button>
</div>
<script>
let latlngs = [
[[45.51, -122.68],
[37.77, -122.43],
[34.04, -118.2]],
[[40.78, -73.91],
[41.83, -87.62],
[32.76, -96.72]]
];
const len = latlngs.length;
let path = L.polyline(latlngs);
let map = L.map('map');
let positron = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>'
}).addTo(map);
map.fitBounds(L.latLngBounds(latlngs));
map.addLayer(L.marker(latlngs[0][0]));
map.addLayer(L.marker(latlngs[len - 1][latlngs[len - 1].length-1]));
map.addLayer(path);
path.bindPopup("Hello world");
function snake() {
path.snakeIn();
}
function snakeOut(){
path.snakeOut();
}
let checkBoxHead = document.getElementById("checkFollowHead");
let followHead = false;
snakeFollow();
function snakeFollow(){
followHead = checkBoxHead.checked; //this can be setup during polyline creation
}
function snakeLaunch(){
path.snakeIn();
setTimeout(function () {
path.snakeOut();
}, 1000)
}
function snakeReset(){
path.snakeReset();
}
path.on('snakeInStart snakeOutStart snakeIn snakeOut snakeInEnd snakeOutEnd', function(ev){
console.log(ev.type);
});
path.on('snakeIn snakeInEnd', function(ev){
if(followHead){
map.setView(ev);
}
});
</script>
</body>
</html>