代码
import * as mapvthree from '@baidumap/mapv-three';
mapvthree.BaiduMapConfig.ak = '您的密钥';
const engine = new mapvthree.Engine(document.getElementById('map'), {
map: {
provider: new mapvthree.BaiduVectorTileProvider(),
center: [120.145, 30.248],
range: 3600,
pitch: 0,
},
widgets: {
scale: {
enabled: true,
},
},
});
const units = {metric: 'metric', imperial: 'us'};
for (const button of document.querySelectorAll('.operate button')) {
button.addEventListener('click', () => {
engine.widgets.scale.unit = units[button.id];
for (const item of document.querySelectorAll('.operate button')) {
const active = item === button;
item.classList.toggle('active', active);
item.setAttribute('aria-pressed', String(active));
}
});
}
滚动地图可观察比例尺随缩放更新。使用按钮可将比例尺切换为公制或英制。
预览