You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GeoJSON popup not working when GeoJSON in FeatureGroup #904
You're right, I'm seeing the problem. If GeoJson is added to a FeatureGroup, a Popup added to the GeoJson object doesn't work. I'm not sure why this is, in the rendered Javascript everything looks as expected.
I'm not sure if this isn't expected behavior for Leaflet though. In Leaflet a GeoJSON object extends FeatureGroup, so maybe they're not supposed to be added to a FeatureGroup.
Do you have any ideas on why this problem is occuring?
Maybe you can try to collect your data in a single geojson description and make a single GeoJson object. That way you don't have a popup per feature though. That functionality still needs to be added to folium. If you want you can add this, PR's are welcome. @jtbaker is working on something similar for tooltips in #883.
@jtbaker you mentioned looking into popups for GeoJson objects, can you chime in on this?
Hi, thanks for having a look and for your comment.
I'm sorry, I am more the end-user type of guy, so that I unfortunately have no suggestion, why it does not work as intended. My current work-around is to add all the GeoJSONs to the main map. But as there are quite a few GeoJSONs I would have preferred to group them in a layer for easy toggling with the layer-control.
I think this issue was solved recently by a new version, or at least it seems like I could add custom popups to a Feature Group
I'm using the version '0.7.0+49.g45a82c6' which is the one by git cloning master branch (it contains the Search feature added by @jtbaker which hasn't been released yet). i don't know if this version has any other difference other than the Search Plugin
The difference with your code is that I'm iterating directly over the GeoJson instead a dataframe
My code:
layer_geom = folium.FeatureGroup(name='layer',control=False)
for i in range(len(data_geojson_dict["features"])):
temp_geojson = {"features":[data_geojson_dict["features"][i]],"type":"FeatureCollection"}
temp_geojson_layer = folium.GeoJson(temp_geojson,
highlight_function=lambda x: {'weight':3, 'color':'black'},
control=False,
style_function=lambda feature: {
'color': 'black',
'weight': 1},
tooltip=folium.features.GeoJsonTooltip(fields=list_tooltip_vars,
aliases=[x.capitalize()+":" for x in list_tooltip_vars],
labels=True,
sticky=False))
folium.Popup(temp_geojson["features"][0]["properties"]["productor"]).add_to(temp_geojson_layer)
temp_geojson_layer.add_to(layer_geom)
layer_geom.add_to(m)
folium.LayerControl(autoZIndex=False, collapsed=True).add_to(m)
When clicking on a GeoJson polygon it shows a custom PopUp (in this case, tonbaf 2006)
As you can see I'm combining a tooltip and the GeoJson popup (which is the point of this issue)
Activity
Conengmo commentedon Jul 10, 2018
You're right, I'm seeing the problem. If
GeoJsonis added to aFeatureGroup, aPopupadded to theGeoJsonobject doesn't work. I'm not sure why this is, in the rendered Javascript everything looks as expected.I'm not sure if this isn't expected behavior for Leaflet though. In Leaflet a
GeoJSONobject extendsFeatureGroup, so maybe they're not supposed to be added to aFeatureGroup.Do you have any ideas on why this problem is occuring?
Maybe you can try to collect your data in a single geojson description and make a single
GeoJsonobject. That way you don't have a popup per feature though. That functionality still needs to be added to folium. If you want you can add this, PR's are welcome. @jtbaker is working on something similar for tooltips in #883.@jtbaker you mentioned looking into popups for
GeoJsonobjects, can you chime in on this?mfredk commentedon Jul 12, 2018
Hi, thanks for having a look and for your comment.
I'm sorry, I am more the end-user type of guy, so that I unfortunately have no suggestion, why it does not work as intended. My current work-around is to add all the GeoJSONs to the main map. But as there are quite a few GeoJSONs I would have preferred to group them in a layer for easy toggling with the layer-control.
davidolmo commentedon Feb 12, 2019
I think this issue was solved recently by a new version, or at least it seems like I could add custom popups to a Feature Group
I'm using the version '0.7.0+49.g45a82c6' which is the one by git cloning master branch (it contains the Search feature added by @jtbaker which hasn't been released yet). i don't know if this version has any other difference other than the Search Plugin
The difference with your code is that I'm iterating directly over the GeoJson instead a dataframe
My code:
When clicking on a GeoJson polygon it shows a custom PopUp (in this case, tonbaf 2006)
As you can see I'm combining a tooltip and the GeoJson popup (which is the point of this issue)
Conengmo commentedon Nov 30, 2022
I can confirm this is no longer an issue, on the main branch at least.