I am trying to use the markers.refreshClusters();
function to refresh the marker icons for a new styled icon I am trying to work with to highlight the selected cluster. Unfortunately, I keep getting the markers.refreshClusters is not a function
error. Is there a file I am missing for the marker cluster plug-in? I tried updating to latest revision of plug-in but it seems I have the latest.
1 Answer
I just wrote the refreshClusters()
method a few weeks ago. Unfortunately it did not make it yet to the distributed version on GitHub nor to the one provided by MapBox, even though the documentation already mentions it.
You can easily add it yourself by copying the code into your script. Just make sure to include it before calling the method.
Demo: http://jsfiddle.net/0ab2hm67/3/
Definitely this new method is helpful to more and more people. Please feel free to ask for a new version to include it by posting on the library issue page.
-
Thank you so much! I thought since documentation had it it would be a native function. You are awesome, thank you for your work. Commented Oct 27, 2015 at 19:13
var markers = L.markerClusterGroup({spiderfyOnMaxZoom: false, showCoverageOnHover: false, zoomToBoundsOnClick: false , iconCreateFunction: function(cluster) { return new L.DivIcon({ html: '<b>' + cluster.getChildCount() + '</b>' });}
is my markercluster group andon("clusterclick")
I am trying to run themarkers.refreshClusters();
and then given the error code. I am not doing anything fancy but for some reason it is not recognizing the refreshClusters as a valid function.console.log(markers)
, what do you get?refreshClusters()
isn't in that list. That means it can't be called on that particular object. If it's a plugin function, it's probably down in eithermap
oroptions
. So you'd callmarkers.options
ormarkers.map
. If you want to create a jsfiddle, I can try to take a better look at it