I am trying to display several layers with information on a Choropleth Map having as base layer the Stamen Terrain and displaying the layers as FeatureGroup. Here is my initial code without overlay control:
map = folium.Map(location=[38.58, 0], zoom_start=3, tiles="Stamen Terrain")
fg_tc = folium.FeatureGroup(name="Totalc")
fg_tc.add_child(folium.GeoJson(data=open('world.json', 'r',
encoding='utf-8-sig').read(),
style_function=lambda x: {
'fillColor': get_at_once(x['properties']['NAME'], 'totalc'),
'color': 'black',
'weight': 1,
'dashArray': '5, 5',
'fillOpacity': 0.75}))
fg_nc = folium.FeatureGroup(name="New", show=False)
fg_nc.add_child(folium.GeoJson(data=open('world.json', 'r',
encoding='utf-8-sig').read(),
style_function=lambda x: {
'fillColor': get_at_once(x['properties']['NAME'], 'new'),
'color': 'black',
'weight': 1,
'dashArray': '5, 5',
'fillOpacity': 0.75}))
fg_td = folium.FeatureGroup(name="Totald", show=False)
fg_td.add_child(folium.GeoJson(data=open('world.json', 'r',
encoding='utf-8-sig').read(),
style_function=lambda x: {
'fillColor': get_at_once(x['properties']['NAME'], 'totald'),
'color': 'black',
'weight': 1,
'dashArray': '5, 5',
'fillOpacity': 0.75}))
fg_ac = folium.FeatureGroup(name="Active", show=False)
fg_ac.add_child(folium.GeoJson(data=open('world.json', 'r',
encoding='utf-8-sig').read(),
style_function=lambda x: {
'fillColor': get_at_once(x['properties']['NAME'], 'active_cases'),
'color': 'black',
'weight': 1,
'dashArray': '5, 5',
'fillOpacity': 0.75}))
map.add_child(fg_tc)
map.add_child(fg_nc)
map.add_child(fg_td)
map.add_child(fg_ac)
map.add_child(folium.LayerControl())
map.save("map1.html")
my problem is that the FeatureGroup layers are selectable by checkbox allowing more than one layer to be selected at a certain time. In my case I would need at one time to have displayed the Stamen Terrain as background and only one active layer and I do not know how to do this.
I have also tried to control the overlay, but then only one single layer can be visible and I am loosing the Stamen Terrain as a background, i.e. the layers are controlled by radio buttons but there is only one group which includes the Stamen Terrain and the data FeatureGroup layers...
Any idea how I could display, as desired: Stamen Terrain as background and only one active at a moment data layer? I am not fixed to use the FeatureGroup, but at the moment my knowledge is limited to this and so far my google fu failed me...
Thanks!
p.s. here are also some printscreens with the try outs: 1&2 are without overlay control and one can see what happens in '2' where more layers are selected. 3&4 are with overlay=False and then only one layer can be active.