Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use the ControlLayer class to add a LayerControl to your map and then specify the ordering of the layers using the add_overlay method of the Map object.

Here's an example code snippet:

import folium

# create map object
m = folium.Map()

# create marker layer
marker_layer = folium.FeatureGroup(name='Markers')
marker = folium.Marker(location=[40.7128, -74.0060])
marker.add_to(marker_layer)

# add layers to map
marker_layer.add_to(m)
folium.LayerControl().add_to(m)

# reorder layers
m.add_child(folium.map.LayerControl(collapsed=False, position='bottomright'))

# display the map
m

In this example, we first create a marker layer and add a marker to it. Then, we add the marker layer to the map and create a LayerControl using the ControlLayer class. Finally, we add the LayerControl to the map and reorder the layers so that the marker layer is on top.