模型动画
加载三维模型,实现动画效果。

<!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%;
}
.btn-group {
position: absolute;
top: 20px;
left: 20px;
color: white;
}
</style>
<script src="https://delivery.mapmost.com/cdn/sdk/webgl/v9.4.0/mapmost-webgl-min.js"></script>
</head>
<body>
<div id="map"></div>
<div class="btn-group">
<button onClick="startA()">开始动画</button>
<button onClick="stopA()">结束动画</button>
</div>
<script>
let map = new mapmost.Map({
container: 'map',
style: "<your style url>",
center: [120.67927020663829, 31.31997024841401],
zoom: 17.5,
pitch: 60,
userId: '***', // 授权码
env3D: {
envMap: '../../../../static/example_data/hdr/venice_sunset_2k_fixed5_1.hdr'
}
});
let modelGroup
map.on('load', function () {
let models_obj = ["../example_data/TRAIN_4B.glb"].map(item => ({
type: 'glb',
url: item
}));
let options = {
id: 'model_id',
type: 'model',
models: models_obj,
center: [120.67727020663829, 31.31997024841401],
callback: function (group, layer) {
modelGroup = group;
modelGroup.setRotation({x: 0, y: 0, z: 90})
}
};
map.addLayer(options);
})
function startA() {
let linePath = [[120.67727020663829, 31.31997024841401], [120.68327020663829, 31.31997024841401]]
modelGroup.followPath({path: linePath, duration: 10000}, cb)
}
function stopA() {
modelGroup.stop();
}
function cb() {
console.log("动画执行完毕!")
}
</script>
</body>
</html>