1

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.

10
  • Do you have code we can take a look at?
    – BDD
    Commented Oct 21, 2015 at 19:26
  • To give a quick example: 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 and on("clusterclick") I am trying to run the markers.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. Commented Oct 21, 2015 at 19:36
  • When you console.log(markers), what do you get?
    – BDD
    Commented Oct 21, 2015 at 19:56
  • imgur.com/e8MyiA3 Commented Oct 21, 2015 at 20:09
  • So you'll notice 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 either map or options. So you'd call markers.options or markers.map. If you want to create a jsfiddle, I can try to take a better look at it
    – BDD
    Commented Oct 21, 2015 at 20:11

1 Answer 1

3

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.

1
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.