代码
import {
BaiduMapConfig,
BaiduVectorTileProvider,
DynamicSky,
Engine,
HorizontalOrbitTracker,
} from '@baidumap/mapv-three';
BaiduMapConfig.ak = '您的密钥';
// 地点检索返回的上海中心大厦 BD-09 坐标,环绕中心设在楼群上方。
const target = [121.511937, 31.239212, 175];
const container = document.getElementById('map');
const aspect = container.clientWidth / container.clientHeight;
const engine = new Engine(container, {
map: {
center: target,
range: 840 / Math.min(1, aspect * 1.7),
pitch: 57,
heading: 315,
provider: new BaiduVectorTileProvider({
displayOptions: {
flat: false,
building: true,
poi: false,
},
}),
},
rendering: {
sky: null,
enableAnimationLoop: true,
},
clock: {
currentTime: new Date(2026, 5, 21, 16),
},
});
engine.add(new DynamicSky());
const horizontal = engine.add(new HorizontalOrbitTracker());
const start = document.querySelector('#horizontal');
const stop = document.querySelector('#stop');
function resetControls() {
start.disabled = false;
stop.disabled = true;
}
start.onclick = () => {
horizontal.start({
center: target,
range: 880 / Math.min(1, aspect * 1.75),
angle: 29,
duration: 10000,
});
start.disabled = true;
stop.disabled = false;
};
stop.onclick = () => {
horizontal.stop();
resetControls();
};
horizontal.onFinish = resetControls;
以陆家嘴的上海中心大厦为环绕中心,从不同方向观察百度三维底图中的楼群和滨水街区。
预览