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.
Asked: 2021-12-13 11:00:00 +0000
Seen: 1 times
Last updated: Mar 07 '22