地图视角连续变换
地图连续飞行实现视角变换。

<!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;
}
</style>
<script src="https://delivery.mapmost.com/cdn/sdk/webgl/v9.2.0/mapmost-webgl-min.js"></script>
</head>
<body>
<div id="map"></div>
<div class="btn-group">
<button onClick="changeViewers()">连续切换视角</button>
</div>
<script>
var map = new mapmost.Map({
container: 'map',
style: "<your style url>",
center: [120.72541613154851, 31.31171803927643],
zoom: 14,
userId: '***', // 授权码
});
let locations = [
{
center: [120.72, 31.4],
zoom: 17,
bearing: 40,
pitch: 60
}, {
center: [120.9, 31.4],
zoom: 17,
bearing: 30,
pitch: 80
}, {
center: [120.72541613154851, 31.31171803927643],
zoom: 17,
bearing: 48,
pitch: 50
}]
function changeViewers() {
let count = 0;
changeViewer(locations[count])
let moveFunc = function () {
changeViewer(locations[count++])
};
map.on('moveend', moveFunc);
}
function changeViewer(location) {
map.flyTo({
...location,
speed: 0.8,
curve: 1,
easing(t) {
return t;
}
});
}
</script>
</body>
</html>