代码
import {
BaiduMapConfig,
BaiduVectorTileProvider,
Engine,
GeoJSONDataSource,
Pillar,
} from '@baidumap/mapv-three';
const container = document.getElementById('map');
const center = [116.3968, 40.0344];
const range = (5200 * 1.42) / Math.min(1.42, container.clientWidth / container.clientHeight);
BaiduMapConfig.ak = '您的密钥';
const provider = new BaiduVectorTileProvider({
displayOptions: {
building: false,
poi: false,
},
});
const engine = new Engine(container, {
map: {
projection: 'EPSG:3857',
center,
range,
pitch: 55,
heading: 0,
provider,
},
rendering: {
sky: null,
},
});
function point(coordinates, properties = {}) {
return {
type: 'Feature',
geometry: {
type: 'Point',
coordinates,
},
properties,
};
}
// 奥森南北园及周边入口的模拟客流量,单位:千人次。
const entrances = [
[116.3886, 40.0431, 17],
[116.395, 40.045, 25],
[116.4008, 40.0441, 18],
[116.3917, 40.039, 15],
[116.3985, 40.039, 20],
[116.3858, 40.0351, 17],
[116.392, 40.0347, 23],
[116.3983, 40.0325, 28],
[116.4053, 40.0341, 19],
[116.3942, 40.0293, 18],
[116.4001, 40.0278, 22],
[116.4063, 40.0286, 16],
];
const source = GeoJSONDataSource.fromGeoJSON(
entrances.map(([lng, lat, count]) => point([lng, lat], {count})),
);
source.defineAttribute('height', (p) => p.count * 30);
const pillars = engine.add(
new Pillar({
shape: 'pillar',
radius: 60,
radialSegments: 32,
openEnded: false,
vertexHeights: true,
gradient: {
0.2: '#467ce3',
0.45: '#25ba3d',
0.7: '#e5c04f',
1: '#d9483b',
},
}),
);
pillars.dataSource = source;
在北京奥林匹克森林公园周边的入口位置绘制热力柱,柱高和颜色按模拟客流量变化。
预览