From 37096e019e187c8db7b6733380d2973b4c62b1c4 Mon Sep 17 00:00:00 2001 From: Rambaud Pierrick <12rambau@users.noreply.github.com> Date: Thu, 27 Jul 2023 21:37:51 +0000 Subject: [PATCH] fix: make the layer group visibility togglable --- ipyleaflet/leaflet.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ipyleaflet/leaflet.py b/ipyleaflet/leaflet.py index 8e981f7f0..770f702eb 100644 --- a/ipyleaflet/leaflet.py +++ b/ipyleaflet/leaflet.py @@ -1211,12 +1211,15 @@ class LayerGroup(Layer): ---------- layers: list, default [] List of layers to include in the group. + visible: bool, default True + the visibility of the layer on the map """ _view_name = Unicode('LeafletLayerGroupView').tag(sync=True) _model_name = Unicode('LeafletLayerGroupModel').tag(sync=True) layers = Tuple().tag(trait=Instance(Layer), sync=True, **widget_serialization) + visible = Bool(True).tag(sync=True) _layer_ids = List() @@ -1341,6 +1344,11 @@ def clear(self): """Remove all layers from the group.""" self.layers = () + @observe("visible") + def toggle_markers(self, visible): + """Switch the layers visibility according to the master LayerGroup.""" + [setattr(layer, "visible", visible["new"]) for layer in self.layers] + class FeatureGroup(LayerGroup): """FeatureGroup abstract class."""