import folium
from folium.plugins import OverlappingMarkerSpiderfier, FeatureGroupSubGroup
# Create a map
m = folium.Map(location=[45.05, 3.05], zoom_start=13)
# Create a main FeatureGroup
main_group = folium.FeatureGroup(name='Main Group')
# Create sub-groups
sub_group1 = FeatureGroupSubGroup(main_group, name='Sub Group 1')
sub_group2 = FeatureGroupSubGroup(main_group, name='Sub Group 2')
# Add markers to the first sub-group
for i in range(10):
folium.Marker(
location=[45.05 + i * 0.0001, 3.05 + i * 0.0001],
popup=f"Sub Group 1 Marker {i}"
).add_to(sub_group1)
# Add markers to the second sub-group
for i in range(10, 20):
folium.Marker(
location=[45.06 + (i - 10) * 0.0001, 3.06 + (i - 10) * 0.0001],
popup=f"Sub Group 2 Marker {i}"
).add_to(sub_group2)
# Add the main group to the map
main_group.add_to(m)
# Add sub-groups to the map
sub_group1.add_to(m)
sub_group2.add_to(m)
# Initialize OverlappingMarkerSpiderfier
oms = OverlappingMarkerSpiderfier()
oms.add_to(m)
# Add the LayerControl plugin
folium.LayerControl().add_to(m)
m