Skip to content

Support GeoJsonToolTips/GeoJsonPopup when using GeoJson together with the marker cluster plugin #1770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
chrgernoe opened this issue May 28, 2023 · 2 comments · Fixed by #2136

Comments

@chrgernoe
Copy link

At the moment, it is possible to use GeoJson and add a tooltip based on the GeoJson property. However, as soon as the marker cluster plugin is used, this doesn't work anymore. Means, the tooltips are just not shown.

I spent a lot of time searching in the internet for a solution but I couldn't find anything. Therefore, I debugged the issues by myself. As a hint: I have experience in Python but I'm not at all a JavaScript expert. So, please excuse possible stupid questions.

The problem with current appraoch in folium is the following: A GeoJsonTooltip object is add as child to the GeoJson object and during code generation this leads to JavaScript code where the bindTooltip method of the GeoJson object is used. According to the Leaflet doc this seems to be right but what actually need to be done is, calling the bindTooltip method of the layer for each feature. I tested this on my fork and it works. With the current implementation, you can even see a Javascript error in the debug console of the browser.

To make it work, I changed the template code of theGeoJsonTooltipobject so that the bindTooltip method of its parent (GeoJsonobject) is not directly called but generates a JavaScript function which must be called in the onEachFeature callback in the generated GeoJson JavaScript code. However, this concept does not feel right. It might be a general solution for the GeoJsonTooltip class but will probably not work for the general Tooltip class or at least breaks existing code.

I thought a bit about a general solution. Maybe an extra argument like on_each_feature in the Python add_child method could indicate the child object to change the generated code so that the parent object can bind the tooltip on each feature instead. But I'm not so familiar with the whole project. Maybe there is a much better solution.

@lmmx
Copy link

lmmx commented Dec 12, 2024

This bug has also been noted here

@hansthen
Copy link
Collaborator

Also see issue #1520 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants