代码
import {
BaiduMapConfig,
BaiduTrafficTileProvider,
BaiduVectorTileProvider,
Engine,
MapView,
} from '@baidumap/mapv-three';
const ak = BaiduMapConfig.ak || '您的密钥';
const hasKey = Boolean(ak.trim()) && !ak.includes('密钥');
if (hasKey) {
BaiduMapConfig.ak = ak;
}
const engine = new Engine('map', {
map: {
projection: 'EPSG:3857',
center: [116.39, 39.907],
pitch: 0,
range: 4_000,
provider: hasKey ? new BaiduVectorTileProvider({ak}) : null,
},
});
engine.add(
new MapView({
terrainProvider: null,
vectorProvider: hasKey ? new BaiduTrafficTileProvider() : null,
}),
);
预览