In [3]:
import os
import folium
print(folium.__version__)
In [10]:
map_1 = folium.Map(location=[46.7594, 2.4011], zoom_start=7,tiles=None)
map_1.add_tile_layer()
data_sites = [{"status": "is_active", "coordinates" : [46.7394, 2.4511]},{"status": "is_active", "coordinates" : [46.5394, 2.2511]},{"status": "not_active", "coordinates" : [46.694, 2.5511]}, {"status": "not_active", "coordinates" : [46.994, 2.9511]}]
create a group with the name of every filter
In [5]:
feature_group_active = folium.FeatureGroup(name='Active')
feature_group_unactive = folium.FeatureGroup(name='Unactive')
separate each of them in their own markerCluster
In [6]:
marker_cluster_active = folium.MarkerCluster()
marker_cluster_unactive =folium.MarkerCluster()
for site in data_sites:
if(site["status"]=="is_active"):
marker_active = folium.Marker(site["coordinates"],popup="OK",icon = folium.Icon(color='green',icon='ok-sign'))
marker_cluster_active.add_child(marker_active)
else:
marker_unactive = folium.Marker(site["coordinates"],popup="KO",icon = folium.Icon(color='red',icon='exclamation-sign'))
marker_cluster_unactive.add_child(marker_unactive)
add filter to specific cluster
In [7]:
feature_group_active.add_child(marker_cluster_active)
feature_group_unactive.add_child(marker_cluster_unactive)
Out[7]:
add filter to map
In [9]:
map_1.add_child(feature_group_active)
map_1.add_child(feature_group_unactive)
Out[9]:
toogle to display some marker
In [ ]:
map_1.add_child(folium.LayerControl())
map_1