[GIS] Getting the childcount in leaflet markercluster

clusteringhtmljavascriptleafletweb-gis

I have created a custom icon for clustering my data, using leaflet markercluster. As default markercluster have the "childcount" in the icon. How can i put that number in my divicon?

var markers = L.markerClusterGroup({
iconCreateFunction: function(cluster) {
    return L.divIcon({className: 'mydivicon', html: 'childcount'});
}
});

of course it just puts the text "childicon" in the circle. The child icon is a 'var' in the leaflet.markercluster-src.js

var childCount = cluster.getChildCount();

How can i write it in my L.divicon?

Best Answer

Okay i have the answer now:

var markers = L.markerClusterGroup({
iconCreateFunction: function(cluster) {
var childCount = cluster.getChildCount();
    return L.divIcon({className: 'mydivicon', html: '<div><span>' + childCount + '</span></div>'});
}
});