轨迹移动点位动画
地图显示轨迹移动点位动画。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>轨迹移动点位动画</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"/>
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
</style>
<script src="https://delivery.mapmost.com/cdn/sdk/webgl/v9.1.1/mapmost-webgl-min.js"></script>
</head>
<body>
<div id="map"></div>
<script>
var map = new mapmost.Map({
container: 'map',
style: "<your style url>",
center: [120.72541613154851, 31.31171803927643],
zoom: 14,
userId: '***', // 授权码
});
let radius = 0.01;
function pointOnCircle(angle) {
return {
"type": "Point",
"coordinates": [
120.72541613154851 + Math.cos(angle) * radius,
31.31171803927643 + Math.sin(angle) * radius
]
};
}
map.on('load', function () {
// 添加一个数据源和一个图层,点会在一个圆中进行轨迹移动。
map.addSource('point', {
"type": "geojson",
"data": pointOnCircle(0)
});
map.addLayer({
"id": "point",
"source": "point",
"type": "circle",
"paint": {
"circle-radius": 10,
"circle-color": "#007cbf"
}
});
function animateMarker(timestamp) {
// 根据动画的时间戳将数据更新到一个新的位置。
// 表达式中的除数 "timestamp / 1000 "控制动画速度。
map.getSource('point').setData(pointOnCircle(timestamp / 1000));
// 请求动画的下一帧。
requestAnimationFrame(animateMarker);
}
// 启动动画。
animateMarker(0);
});
</script>
</body>
</html>