Search code examples
javascriptleafletmarkerclusterer

Leaflet: auto change color of cluster / or spiderfy to chosen marker in cluster.


I am current practicing on Leaftlet Marker Cluster.

1. If I know the marker I need is under a cluster, how can I automatically spiderfy that cluster to the max zoom level that obtain the marker I need without clicking onto the cluster?

2. If I know the marker in that cluster, how can I auto changing color of that cluster so I know that the marker I need to find is under that cluster.


Solution

    1. Down the page on the github repo you listed above, I found this method that might answer your first question:
    • zoomToShowLayer(layer, callback): Zooms to show the given marker (spiderfying if required), calls the callback when the marker is visible on the map.
    1. It looks like these methods could be used to update the styling for a single cluster based on a single marker within that cluster:

    If you have customized the clusters icon to use some data from the contained markers, and later that data changes, use this method to force a refresh of the cluster icons. You can use the method: ...

    • with a single marker.

    Specifically:

    // If updating only one marker, pass true to
    // refresh this marker's parent clusters right away.
    myMarker.refreshIconOptions(optionsMap, true);