Leaflet.markercluster
Leaflet.markercluster copied to clipboard
Tooltips don't get unbound when clusters are recomputed
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.
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.
Okay, I'll put in a PR for a note in the documentation soon.
Is there an option to bind a tooltip for cluster-markers to the layer now? If so, I couldn't find it...