-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
91 lines (74 loc) · 2.55 KB
/
demo.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Display a map</title>
<meta property="og:description" content="Initialize a map in an HTML element with MapLibre GL JS." />
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel='stylesheet' href='https://unpkg.com/maplibre-gl@3.6.2/dist/maplibre-gl.css' />
<script src='https://unpkg.com/maplibre-gl@3.6.2/dist/maplibre-gl.js'></script>
<script src="https://cdn.jsdelivr.net/npm/@turf/turf@5/turf.min.js"></script>
<script src="index.js"></script>
<style>
body { margin: 0; padding: 0; }
html, body, #map { height: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script>
const map = new maplibregl.Map({
container: 'map', // container id
style: 'https://demotiles.maplibre.org/style.json', // style URL
center: [0, 0], // starting position [lng, lat]
zoom: 1 // starting zoom
});
// generate some sample data
let lines = [];
for (i=0; i<4; i++) {
lines.push(turf.lineString([[-90, 80-i*20],[90, 80-i*20]]))
}
map.on('load', e=>{
// continuous looping animation
const looping = new LineAnimation('looping',{
dashLength:1,
duration:1500,
loop: true,
headColor: `rgba(200,0,0,1)`,
tailColor: `rgba(200,0,0,0)`,
backgroundColor: `rgba(200,0,0,0)`,
geojson: lines[0]
});
looping.addTo(map);
// animation starting/stopping by mouse click
const startStop = new LineAnimation('startStop',{
dashLength:1,
duration:500,
loop: true,
headColor: `rgba(0,200,0,1)`,
tailColor: `rgba(0,200,0,0)`,
backgroundColor: `rgba(0,200,0,0)`,
geojson: lines[1]
});
startStop.addTo(map);
map.on('click', e=>{
if (startStop.playing) startStop.pause()
else startStop.play()
});
// animation that tracks the cursor's horizontal position
const cursorAnimation = new LineAnimation('cursorAnimation',{
dashLength:1,
headColor: `rgba(0,0,200,1)`,
tailColor: `rgba(0,0,0,0)`,
backgroundColor: `rgba(0,0,200,0)`,
geojson: lines[2]
});
cursorAnimation.addTo(map);
map.on('mousemove', e=>{
const{point} = e;
cursorAnimation.setProgress(point.x/innerWidth)
})
})
</script>
</body>
</html>