0

I was wondering if there is a way in Folium to get the information on an entity we click on with Folium?

I'd like the map to either open a tab with the attribute information or just send back information on the entity selected without necessarily using a popup.

1

There seems to not be support for this in Folium as yet. Quoting from the issue regarding dynamically change/update markers:

"It's import(ant) to understand that folium generates the html with Leaflet javascript. So anything that happens on the map after generation is outside of folium's scope"

See here for more detail

  • Since posting this I found a work-around here (the work-around code is in the comment by @davidolmo on Feb 12). But also, there's a pull request that would seemingly resolve this, and it's under review at present here – Grizzly2501 Apr 10 at 5:38
0

You can use GeoJsonTooltip to show selected fields from a GeoDataFrame.

usmap = folium.Map(
    location=[40,-95],
    tiles='cartodbpositron',
    zoom_start=5,
    control_scale=True
)

folium.GeoJson(
    states[['STATE_NAME', 'geometry']].to_json(),
    name='States',
    show=True,
    style_function=lambda x: {
        'fillColor': 'lightblue',
        'color': 'black',
        'weight': 1,
        'fillOpacity':0.7
    },
    highlight_function=lambda x: {
        'fillOpacity':1
    },
    tooltip=folium.features.GeoJsonTooltip(
        fields=['STATE_NAME'],
        aliases=['State name:'],
    ),
).add_to(usmap)
  • Thank you for your answer, indeed i do use GeoJsonTooltip for looking at specific informations but what if I'd like to export the information of a specific area when clicking on an entity ? – Brocolus Feb 24 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.