Leaflet markercluster - 百分比而不是 Children 的数量
Leaflet maerkercluster - Percentage instead of number of Children
在很多情况下我需要markercluster,显示地图中标记总数的比率(以%的形式)而不是children的数量的数量会很有趣集群。因此,如果该集群中有 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;
}
再次感谢您
您可以使用这个 puglin:
https://github.com/Leaflet/Leaflet.markercluster
示例:
http://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-realworld.388.html
http://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-custom.html
要计算百分比,请阅读以下部分:
https://github.com/Leaflet/Leaflet.markercluster#customising-the-clustered-markers
getChildCount()
或 getAllChildMarkers()
提供所有分数
在很多情况下我需要markercluster,显示地图中标记总数的比率(以%的形式)而不是children的数量的数量会很有趣集群。因此,如果该集群中有 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;
}
再次感谢您
您可以使用这个 puglin: https://github.com/Leaflet/Leaflet.markercluster
示例:
http://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-realworld.388.html
http://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-custom.html
要计算百分比,请阅读以下部分:
https://github.com/Leaflet/Leaflet.markercluster#customising-the-clustered-markers
getChildCount()
或 getAllChildMarkers()
提供所有分数