-
Notifications
You must be signed in to change notification settings - Fork 0
/
动态画线.html
120 lines (114 loc) · 4.12 KB
/
动态画线.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
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>动态画线</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<link rel="stylesheet" href="css/mapbox-gl.css" type="text/css"/>
<script type="text/javascript" src="js/mapbox-gl.js"></script>
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<style>
button {
position: absolute;
margin: 20px;
}
#pause::after {
content: 'Pause';
}
#pause.pause::after {
content: 'Play';
}
</style>
<div id='map'></div>
<!-- <button id='pause'></button> -->
<script>
var map = new mapboxgl.Map({
container: 'map', // container id
style: { // stylesheet location
"version": 8,
"sources": {},
"layers": []
},
center:[118.6809,32.0502], // starting position [lng, lat]
zoom: 10 // starting zoom
});
map.on("load",function(){
var arcgis_wmts ='http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer/WMTS?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=ChinaOnlineCommunity&STYLE=default&TILEMATRIXSET=default028mm&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&FORMAT=image/png'
var arcgis_layer = {
"id": "arcgis_wmts",
"type": "raster",
"source": {
"type": "raster",
"tiles": [arcgis_wmts],
"zoomOffset": 0,//wmts Capabilities信息中TileMatrix第一个对应的实际多少级
"tileSize": 256
}
};
map.addLayer(arcgis_layer);
})
var geojson = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[118.8367,32.1201],
]
}
}]
};
var path = [
[118.8308,32.1006],
[118.8281 ,32.0947],
[118.8264 ,32.0865],
[118.8246, 32.0717],
[118.8143, 32.0405],
[118.7859 ,31.9838],
[118.7793, 31.9615],
[118.6750, 31.8547],
[118.5939, 31.8616],
[118.4648 ,31.8973],
[118.4360 ,31.9330],
[118.4182 ,31.9852]
];
map.on('load', function() {
map.addLayer({
'id': 'line-animation',
'type': 'line',
'source': {
'type': 'geojson',
'data': geojson
},
'layout': {
'line-cap': 'round',
'line-join': 'round'
},
'paint': {
'line-color': 'red',
'line-width': 15,
'line-opacity': 1
}
});
var i = 0
function animateLine() {
geojson.features[0].geometry.coordinates.push(path[i]);
i ++;
map.getSource('line-animation').setData(geojson);
setTimeout(animateLine,200)
// animation = requestAnimationFrame(animateLine);
}
animateLine();
});
//创建marker
new mapboxgl.Marker()
.setLngLat([118.8367,32.1201])
.addTo(map);
</script>
</body>
</html>