在许多情况下我需要markercluster,显示地图中标记总数的比率(以%的形式)而不是集群的子节点数量会非常有趣。因此,如果您在该集群中有 20 个制造商并且地图中的总数为 200,我希望它在地图的该区域显示 10% 而不是 20。
任何人都知道如何实现它?
谢谢你
感谢您的解决方案,它非常简单并且效果很好,这是解决方案的代码:
$.getJSON(link, function(data) {
var total_number = data.features.length; //Here I get the total number of markers
var others = L.geoJson(data, {
onEachFeature: function (feature, layer) {
layer.bindPopup('Number: ' + feature.properties.Nr+' Residency:'+ feature.properties.Lives);
},
})
var markers = L.markerClusterGroup({
iconCreateFunction: function(cluster) {
var markers = cluster.getAllChildMarkers();
var n = ((markers.length/total_number)*100).toFixed(1);;
return L.divIcon({ html: n+'%', className: 'mycluster', iconSize: L.point(40, 40) });
},
});
“myclusters”的 CSS 如下:
.mycluster {
width: 150px;
height: 15px;
background-color: greenyellow;
text-align: center;
font-size: 18px;
}
再次感谢你