Leaflet.markercluster icon indicating copy to clipboard operation
Leaflet.markercluster copied to clipboard

Tooltips don't get unbound when clusters are recomputed

Open Azmisov opened this issue 7 years ago • 3 comments

Test case: https://jsfiddle.net/azmisov/zm7Ls1L7/ You can see two tooltips overlapping. The tooltip is set in the iconCreateFunction.

Not sure if this is really a bug. I'm guessing you reuse the older cluster object for performance reasons, and so any previous tooltips will still be bound to it. It is also confusing because the tooltips are not attached to the display icon, but the containing cluster (marker?) object. The double tooltip behavior can be fixed by adding cluster.unbindTooltip() before you bind the tooltip.

I'm not sure really what the "correct" behavior should be. AFAIK, the only way to attach tooltips is via the iconCreateFunction, so maybe by default it should call unbindTooltip before passing the cluster to this callback? Or perhaps just a note in the documentation about this behavior would suffice.

Azmisov avatar Jan 18 '18 22:01 Azmisov

I'm not sure if you should be using iconCreateFunction for binding tooltips. That will be called every time the icon may need updating (ex: when the child markers change). I think this is an app bug rather than a MCG bug, happy to have a PR for some documentation however.

danzel avatar Jan 19 '18 02:01 danzel

Okay, I'll put in a PR for a note in the documentation soon.

Azmisov avatar Feb 01 '18 22:02 Azmisov

Is there an option to bind a tooltip for cluster-markers to the layer now? If so, I couldn't find it...

ray007 avatar Jan 15 '20 15:01 ray007