Skip to content

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

@chrgernoe

Description

@chrgernoe

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions