forked from mapbox/mapbox-gl-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimate.html
107 lines (91 loc) · 2.49 KB
/
animate.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
<!DOCTYPE html>
<html>
<head>
<title>Mapbox GL JS debug page</title>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel='stylesheet' href='../dist/mapbox-gl.css' />
<style>
#map { width: 1200px; height: 800px; }
</style>
</head>
<body>
<div id='map'></div>
<script src='../dist/mapbox-gl-dev.js'></script>
<script src='../debug/access_token_generated.js'></script>
<script>
var map = window.map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
center: [0, 0],
zoom: 4
});
var radius = 30;
function line(angle, radius) {
return {
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[-Math.cos(angle) * radius, -Math.sin(angle) * radius + 1],
[Math.cos(angle) * radius, Math.sin(angle) * radius + 1],
]
}
};
}
function crossWithAngle(angle) {
return {
"type": "FeatureCollection",
"features": [
line(angle - Math.PI / 4, radius),
line(angle + Math.PI / 4, radius)
]
};
}
map.on('load', function () {
// Add a source and layer displaying a point which will be animated in a circle.
map.addSource('lines', {
"type": "geojson",
"data": crossWithAngle(0)
});
map.addLayer({
"id": "lines",
"source": "lines",
"type": "line",
"paint": {
"line-width": 4,
"line-color": "#007cbf"
}
});
map.addLayer({
"id": "dot",
"source": "lines",
"type": "circle",
"paint": {
"circle-radius": 10,
"circle-color": "#007cbf"
}
});
var updates = 0;
map.on('data', function (d) {
if (d.sourceDataType === 'content') {
updates++;
}
});
setInterval(function () {
console.log(updates + ' updates per second');
updates = 0;
}, 1000);
function animateMarker(timestamp) {
// Update the data to a new position based on the animation timestamp. The
// divisor in the expression `timestamp / 1000` controls the animation speed.
map.getSource('lines').setData(crossWithAngle(timestamp / 1000));
// Request the next frame of the animation.
requestAnimationFrame(animateMarker);
}
// Start the animation.
animateMarker(0);
});
</script>
</body>
</html>