I want to make an "interactive" map with multiple layers using geopandas explore() function and folium. I was able to generate exactly what I aim for, with one exception: the constraint that only one layer would be allowed at a time. In other words, I want that if someone click on the layer "Adaptation climat ☀❄️", then the layer that was previously selected is automatically unselected and only "Adaptation climat ☀❄️" is displayed.
I looked online for hours and did not find a solution. I guess it's at the LayerControl() level of Folium but I can't find the solution.
I found FeatureGroup layer control in Folium - only one active layer that is related but does not give an answer.
Thanks in advance for your help!
The html map obtained looks like:
And the code is:
list_var = ['note_vetuste', 'note_encadrement', 'note_climat', 'note_cantine', 'note_abord_securise']
list_var_display = ['Vétusté des locaux ', 'Moyens humains ', 'Adaptation climat ☀❄️', 'Cantine ', 'Sécurisation des abords ♀️']
m = gdf[['ecole', list_var[0], list_var[0]+'_count', 'geometry']].explore(
column=list_var[0],
cmap = 'RdYlGn',
marker_kwds=dict(radius=10, fill=True),
legend=False,
tooltip=False,
popup=True,
k=5, # use 10 bins
vmin=1, vmax=5,
tiles=None,
legend_kwds=dict(caption='',colorbar=True, fmt="{:5.2f}"),
name=list_var_display[0],
missing_kwds={'color': 'darkgrey'}
)
list_var.pop(0)
list_var_display.pop(0)
for k, var in enumerate(list_var):
gdf[['ecole', var, var+'_count', 'geometry']].explore(
m=m,
column=var,
marker_kwds=dict(radius=10, fill=True),
cmap='RdYlGn',
tooltip=False,
popup=True,
legend=False,
k=5, # use 10 bins
vmin=1, vmax=5,
name=list_var_display[k], # name of the layer in the map
missing_kwds={'color': 'darkgrey'},
show=False
)
folium.TileLayer('cartodbpositron', control=False).add_to(m) # use folium to add alternative tiles
folium.LayerControl(position="topleft", collapsed=False).add_to(m) # use folium to add layer control
m.save("carte.html")