代码
import {
BaiduMapConfig,
BaiduVectorTileProvider,
EffectPoint,
Engine,
GeoJSONDataSource,
SimplePoint,
} from '@baidumap/mapv-three';
BaiduMapConfig.ak = '您的密钥';
const container = document.getElementById('map');
const aspect = container.clientWidth / container.clientHeight;
const engine = new Engine(container, {
map: {
projection: 'EPSG:3857',
center: [120.151514, 30.250787],
range: Math.max(930, 1_100 / aspect),
pitch: 18,
provider: new BaiduVectorTileProvider({
displayOptions: {
building: false,
poi: false,
},
}),
},
rendering: {
enableAnimationLoop: true,
},
});
const locations = [
[120.149214, 30.251287, 6],
[120.153114, 30.249687, 6],
[120.152914, 30.252387, 6],
];
const source = GeoJSONDataSource.fromGeoJSON(
locations.map((coordinates) => ({
type: 'Feature',
geometry: {type: 'Point', coordinates},
})),
);
const stations = engine.add(
new SimplePoint({
color: '#19566f',
size: 8,
depthTest: false,
}),
);
stations.dataSource = source;
let effect;
function showEffect(type) {
// type 在创建材质时决定。同一份数据换用新的特效图层。
if (effect) engine.remove(effect);
effect = engine.add(
new EffectPoint({
type,
size: 144,
color: '#bb3919',
sideColor: '#984b38',
duration: 2300,
keepSize: false,
}),
);
effect.dataSource = source;
engine.requestRender();
}
const menu = document.getElementById('effect');
showEffect(menu.value);
menu.addEventListener('change', () => showEffect(menu.value));
在西湖设置三个特效点,用同一份数据对比 EffectPoint 的七种 type。切换菜单会同时更新全部点位。
预览