From 719c3a7747f3f1e9b1fb379479e78c7f98ce4eb5 Mon Sep 17 00:00:00 2001 From: Pierrick Rambaud Date: Fri, 24 Mar 2023 11:24:25 +0100 Subject: [PATCH] feat: add visible trait to MarkerCluster MarkerCluster can now control the visiblity of the underlying markers --- ipyleaflet/leaflet.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ipyleaflet/leaflet.py b/ipyleaflet/leaflet.py index 8e981f7f0..d7fbcedb2 100644 --- a/ipyleaflet/leaflet.py +++ b/ipyleaflet/leaflet.py @@ -1191,16 +1191,26 @@ class MarkerCluster(Layer): ---------- markers: list, default [] List of markers to include in the cluster. + visible: bool, default True + the visibility of the layer on the map """ _view_name = Unicode('LeafletMarkerClusterView').tag(sync=True) _model_name = Unicode('LeafletMarkerClusterModel').tag(sync=True) markers = Tuple().tag(trait=Instance(Layer), sync=True, **widget_serialization) + visible = Bool(True).tag(sync=True) + # Options disable_clustering_at_zoom = Int(18).tag(sync=True, o=True) max_cluster_radius = Int(80).tag(sync=True, o=True) + @observe("visible") + def toggle_markers(self, visible): + """Switch the markers visibility according to the master cluster.""" + for marker in self.markers: + marker.visible = visible["new"] + class LayerGroup(Layer): """LayerGroup class.