-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Problem adding layers by for loop #1857
Comments
Did you already already find a solution for that? |
I found a workaround. You must use folium.Choroplet and then access the underlying geojson and cmap. Here is the code I used, you can modify it with your own GeoJson dataframe: mapita = folium.Map()
fg_lst = []
# Solamente nos interesan las columnas de data
for i, col in enumerate(regiones_data.columns):
if col in ["CUT_REG", "REGION"]:
continue
choropleth = folium.Choropleth(
geo_data=regiones,
name=col,
data=regiones_data,
columns=["CUT_REG", col],
key_on="feature.properties.CUT_REG",
fill_color="YlOrRd",
fill_opacity=0.7,
line_opacity=0.2,
legend_name=col,
highlight=True,
line_color="white",
)
folium.GeoJsonTooltip(
fields=["REGION_x", col],
aliases=[field.title() for field in ["REGION_x", col]],
style="background-color: white; color: #333333; font-family: arial; font-size: 12px; padding: 10px;",
localize=True,
).add_to(choropleth.geojson)
fg = folium.FeatureGroup(col)
choropleth.geojson.add_to(fg)
mapita.add_child(fg)
mapita.add_child(choropleth.color_scale)
mapita.add_child(BindColormap(fg, choropleth.color_scale))
fg_lst.append(fg)
GroupedLayerControl(
groups={"Groups": fg_lst},
collapsed=False,
).add_to(mapita)
mapita |
I'm trying to replicate your issue, but not succeeding so far. Can you provide a minimal, standalone code snippet that reproduces your issue? Here's what I tried what worked for me:
|
So for some reason if I try to add multiple groups via a for loop, it just keep the last one. Different story if I add them one by one.
This is my code:
The text was updated successfully, but these errors were encountered: