代码
const map = new BMap.Map('map');
map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
var layer = new BMap.ClusterLayer({
renderStage: 'poi',
});
layer.setData(randomPoints(5000));
map.addLayer(layer);
/**
* 随机点数据(北京附近),properties.count 用于自定义样式演示
*/
function randomPoints(n, spread) {
spread = spread || 1;
var feats = [];
for (var i = 0; i < n; i++) {
feats.push({
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [116.1 + Math.random() * 0.6 * spread, 39.7 + Math.random() * 0.45 * spread],
},
properties: {count: Math.round(Math.random() * 100), name: 'poi_' + i},
});
}
return {type: 'FeatureCollection', features: feats};
}
使用 BMap.ClusterLayer 实现点聚合效果
预览