Skip to content

Is there a feature to make multiple layer controls in folium python with different data? #1484

Closed

Description

@gmehta1996

I am trying to plot some data using folium maps.
Below is my python code and a screenshot.

image

    india_coord = [lat,long]
	my_map = folium.Map(location = india_coord,zoom_start=5,tiles=None,overlay=False)
	feature_group = folium.FeatureGroup(name='Central Region',overlay=True)
	feature_group2 = folium.FeatureGroup(name='South Region',overlay=True)
	feature_group3 = folium.FeatureGroup(name='East Region',overlay=True)
	feature_group4 = folium.FeatureGroup(name='West Region',overlay=True)
	feature_group5 = folium.FeatureGroup(name='North Region',overlay=True)

	feature_group.add_to(my_map)
	feature_group2.add_to(my_map)
	feature_group3.add_to(my_map)
	feature_group4.add_to(my_map)
	feature_group5.add_to(my_map)

	c1 = folium.Choropleth(
		geo_data = india,
		name = 'India',
		legend_name = 'India',
		fill_color = 'orange',
		fill_opacity = 0.3,
		highlight = True).add_to(my_map)

	folium.TileLayer('openstreetmap',overlay=False,name = f'SUMMARY {summ_date}').add_to(my_map)
	

	folium.LayerControl().add_to(my_map) 

    folium.Marker(location,tooltip = data1,popup = popup, icon=folium.Icon(color='cadetblue',icon = 'fa-industry', prefix='fa')).add_to(feature_group)
    ...
    ...
    ...
    folium.Marker(location,tooltip = data1,popup = popup, icon=folium.Icon(color='cadetblue',icon = 'fa-industry', prefix='fa')).add_to(feature_group5)
    my_map.add_child(feature_group)
	my_map.add_child(feature_group2)
	my_map.add_child(feature_group3)
	my_map.add_child(feature_group4)
	my_map.add_child(feature_group5)

With this code I get the map above but I need to make another layer control option for another summary.
For ex. if I add another

folium.LayerControl().add_to(my_map)

to my code I get the following:

image

But this layer control has the same options as the above summary.
Is there a way in folium to create different layer controls with different data on the same map so that If I am selecting the first summary in the first layer control I get the data like in image1 but if I choose the below layer control the data is displayed according to that particular layer control.
How do I link different data with different layer control to view them on the same map.Is there a feature in folium like this?
Thank you

Activity

  1. yoshida-thiago commented on Jan 6, 2022

    @yoshida-thiago

    I am having the same problem! Were you able to find a solution? Any help would be appreciated!

  2. Conengmo commented on Nov 18, 2022

    @Conengmo
    Member

    We added a new plugin called GroupedLayerControl (#1592) which might be helpful here. It will be in the upcoming 0.14.0, or you can get folium directly from our main branch now.

    Other than that I'm afraid I can't help you at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions