是否可以仅在同一坐标上聚类标记? 使用地图框标记聚类时,所有标记都会根据地图缩放级别进行分组。我想做的是让所有标记独立(非分组),除了相同纬度 - 经度坐标上的标记。
这可能吗?
答案 0 :(得分:0)
这不是一个完美的解决方案,但它会完成这项工作...... 我通过使用两个图层组解决了我的问题,一个用于单个标记,另一个用于聚类标记。
这样的事情:
var overlay1 = L.layerGroup().addTo(map);//this one is for single markers
var overlay2 = L.layerGroup().addTo(map);//this one is for clustered
var layers;
//load markers from external source
var featureLayer = L.mapbox.featureLayer()
.loadURL('/my_geojson_script/')
.on('ready', function(e) {
layers = e.target;
//go and do the filtering
doTheThing();
})
function doTheThing()
overlay1.clearLayers();//remove all single markers
overlay2.clearLayers();//remove all clustered
var clusterGroup = new L.MarkerClusterGroup().addTo(overlay2);
layers.eachLayer(function(layer) {
//the number of markers on this layer coordinates (info collected from json property. I calculate this in advance)
var numberOfMarkers = layer.feature.properties.numberOfMarkers;
//if number of markers is greater than 1 add layer to cluster group
if(numberOfMarkers>1){
clusterGroup.addLayer(layer);
}
else{//if number of markers is 1 add layer to individual layer group
overlay1.addLayer(layer);
}
});
}