Search code examples
pythonstreamlitfolium

Set Uncheck The Folium Basemap layers as default value


I created a folium map on streamlit. I added several basemap with this code:

basemaps['Google Maps'].add_to(map)
basemaps['Google Satellite Hybrid'].add_to(map)
basemaps['Google Terrain'].add_to(map)
basemaps['Esri Satellite'].add_to(map)
folium.LayerControl().add_to(map)

My expectation is the default value is uncheck. Unfortunately on folium LayerControl all basemaps are checked like this:

all basemaps are checked

Any solution to make the default value is unchecked?


Solution

  • I believe you want to add these basemaps as different mapstyles. So the solution should be, that the styles are added as radiobuttons, not checkboxes?

    Would look somthing like this:

    import folium
    
    
    #### define map with selectable styles
    
    geo_start = [52.5172, 13.3024]
    dmap = folium.Map(location=geo_start,
                      zoom_start=8,
                      tiles='OpenStreetMap'
                      )
    
    
    mapstyle_2 = folium.raster_layers.TileLayer(tiles='CartoDB dark_matter',
                                                name='dark',
                                                overlay=False,
                                                control=True,
                                                show=True,
                                                )
    mapstyle_2.add_to(dmap)
    
    
    # the layercontrol itself
    lc = folium.map.LayerControl(collapsed=False)
    lc.add_to(dmap)
    
    dmap