[GIS] Turn Layer off by default in Leaflet LayerControl

foliumlayer-controlleafletpython

In the following python code I have three data layers while I need to show only two of them by default as the program executes. So the Places and District layer should be checked as the map is opened and the Country layer should be unchecked/turned off. What should I write in LayerControl for this?

import folium
import pandas

data=pandas.read_csv("Previous.csv")
data = data[data['Death'] > 0]
lat = list(data["Latitude"])
lon = list(data["Longitude"])
dat = list(data["Date"])
are = list(data["Area"])
sym = list(data["Symptoms"])
tra = list(data["Area_traveled"])
sou = list(data["Source"])
dea = list(data["Death"])

def color_producer(elevation):
    if elevation <= 1:
        return 'orange'
    elif 1 < elevation <= 3:
        return 'red'
    elif 3 < elevation :
        return 'darkred'


fga = folium.FeatureGroup(name="Places")
map = folium.Map(location=[23.789412, 90.351756], zoom_start=7, tiles="Mapbox Bright")
for lt, ln, co, mo, vi, up, na, de  in zip(lat, lon, dat, are, sym, tra, sou, dea):
    fga.add_child(folium.CircleMarker(location=[lt, ln], radius = str(de), popup= "<br><a href="+na+">Link </a></b>" + na + "<br><b>Area: </b>" + co + "<br><b>Symptoms : </b>" + vi + "<br><b>Area traveled : </b>" + mo+ "<br><b>Source : </b>" + up,
    fill = 'true', fill_color = color_producer(de), color = 'grey', fill_opacity=0.7))

fgp = folium.FeatureGroup(name="District")
fgp.add_child(folium.GeoJson(open("dist.geojson",encoding = "utf-8-sig").read(), style_function=lambda x: {'fillColor':'grey' if x['properties']['Death'] == 0
else 'darkred'}))

fgq = folium.FeatureGroup(name="Country")

fgq.add_child(folium.GeoJson(open("world.json",encoding = "utf-8-sig").read(), style_function=lambda x: {
'fillColor': 'none'}))

map.add_child(fga)
map.add_child(fgp)
map.add_child(fgq)
map.add_child(folium.LayerControl())
map.save("Corona.html")

Best Answer

I've never used Python, but if you look at the Folium docs at https://python-visualization.github.io/folium/modules.html?highlight=featuregroup#folium.map.FeatureGroup, you'll se that folium.map.FeatureGroup class has show parameter.

Docs say: show (bool, default True) – Whether the layer will be shown on opening (only for overlays). Setting this parameter to false should do it.