I am using Dash Leaflet and trying to set up tooltips on a geojson feature that return the site name based upon its properties. The geojson data contains lots of polygons so the name returned should be the polygon that is hovered over.
I am using the below code and use the thread below to implement - however, as long as my mouse is hovering over the polygon, the callback will keep firing many times rather than just once and returning the name. Is there a way to solve this or a better method?
@Emil, do you know if there is a way to add the ‘sticky’ property to a tooltip when doing this? I’m displaying tooltips for a GeoJson polygon layer, and would prefer the tooltip position to follow the mouse.
It’s a straightforward set of world boundaries, and I get some slightly weird tooltip placement with the defaults. (The mouse position was near the western end of Russia when I did this screengrab)
I’ve realised that what I called the ‘weird’ tooltip placement happens only when the features are MultiPolygons. If Multipolygons are exploded into multiple records with Polygon geometry, then the tooltip always appears at the centroid of the polygon that the mouse is hovering over.
If I can get my other functionality working with a Polygon file, this looks like it gives a good enough solution without having to use sticky tooltips
I’m showing clustered markers for countries, and can customise the icon etc. for those. At the same time I’d like to show a tooltip when I hover over a country, and hope to customise the appearance of those, and hopefully also to filter them so that the hover tooltips don’t duplicate visible marker labels.
That looks like a good solution. If you want to realise your initial idea, you could bind the popup explicitly using the onEachFeature handle,
This is what is going on “under the hood”, when you add a tooltip property. However, by doing it explicitly as the example above, you should be able to customize the tooptip as you like - for example making it sticky. You can see all options here,