I'm facing an issue with Leaflet clustering. I use v-marker-cluster. In the icon createFunction of the cluster, I'm using children className to determine the style of the cluster. Here is a part of this function :
const childCount = marker_cluster._markers.filter((marker) => marker.options.icon.options.className.includes("selected")).length;
// other things that do not affect childCount
return new L.DivIcon({
html: "<div>" + childCount + "</div>",
className: childCount == 0 ? "class1" : "class2"),
});
But when doing that, I saw that sometimes I have class1 even if the cluster have some child with selected class. To be sure, I checked the object marker_cluster and I found that _childCount is equal to 2 and _markers is empty.
How is this even possible ? Isn't _markers the reprezentation of the children elements ? (It works most of the time but I don't know why, sometimes, it's empty)
I found out that you should access the childMarkers
with getAllChildMarkers()
methods to avoid this kind of issue