From f36d97b317cf744feaba5bef725a323b5241ec2a Mon Sep 17 00:00:00 2001 From: Riccardo Porreca Date: Mon, 22 Jul 2024 15:25:46 +0200 Subject: [PATCH 1/4] Make Leaflet-Geoman ignore created layers by default, fixes #1215 --- python/ipyleaflet/ipyleaflet/leaflet.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/ipyleaflet/ipyleaflet/leaflet.py b/python/ipyleaflet/ipyleaflet/leaflet.py index 5ce862e6..c562e49a 100644 --- a/python/ipyleaflet/ipyleaflet/leaflet.py +++ b/python/ipyleaflet/ipyleaflet/leaflet.py @@ -171,6 +171,8 @@ class Layer(Widget, InteractMixin): Interactive widget that will be shown in a Popup when clicking on the layer. pane: string Name of the pane to use for the layer. + pm_ignore: boolean + Make Leaflet-Geoman ignore the layer, so it cannot modify it. """ _view_name = Unicode("LeafletLayerView").tag(sync=True) @@ -195,6 +197,8 @@ class Layer(Widget, InteractMixin): options = List(trait=Unicode()).tag(sync=True) subitems = Tuple().tag(trait=Instance(Widget), sync=True, **widget_serialization) + pm_ignore = Bool(True).tag(sync=True, o=True) + @validate("subitems") def _validate_subitems(self, proposal): """Validate subitems list. From 14c36a8ad5cf4b1629ac8beaa4652a48ba3e4f4a Mon Sep 17 00:00:00 2001 From: Riccardo Porreca Date: Mon, 22 Jul 2024 15:31:30 +0200 Subject: [PATCH 2/4] Fix existing Geoman documentation list, not rendered as such --- docs/controls/geoman_draw_control.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/controls/geoman_draw_control.rst b/docs/controls/geoman_draw_control.rst index c0046329..20141011 100644 --- a/docs/controls/geoman_draw_control.rst +++ b/docs/controls/geoman_draw_control.rst @@ -1,10 +1,11 @@ Geoman Draw Control -============ +=================== -``GeomanDrawControl`` allows one to draw various shapes on the map. +``GeomanDrawControl`` allows one to draw various shapes on the map. The drawing functionality on the front-end is provided by `geoman `_. The following shapes are supported: + - marker - circlemarker - circle From 04ac2e8cfe11eaddfd5cf5699639a45f0ad0d9e9 Mon Sep 17 00:00:00 2001 From: Riccardo Porreca Date: Mon, 22 Jul 2024 16:38:47 +0200 Subject: [PATCH 3/4] Document `pm_ignore=False` in Geoman Draw Control documentation page --- docs/controls/geoman_draw_control.rst | 11 ++++++++++- docs/layers/index.rst | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/controls/geoman_draw_control.rst b/docs/controls/geoman_draw_control.rst index 20141011..7d50b6b5 100644 --- a/docs/controls/geoman_draw_control.rst +++ b/docs/controls/geoman_draw_control.rst @@ -25,11 +25,14 @@ Additionally, there are modes that allow editing of previously drawn shapes: To have a drawing tool active on the map, pass it a non-empty dictionary with the desired options, see `geoman documentation `_ for details. +By default, editing is disabled for shapes created programmatically as described in the :ref:`layers-section` page. +However, adding ``pm_ignore=False`` to shapes allows them to be modified using the control. + Example ------- .. jupyter-execute:: - from ipyleaflet import Map, GeomanDrawControl + from ipyleaflet import Map, GeomanDrawControl, Circle m = Map(center=(50, 354), zoom=5) @@ -65,6 +68,12 @@ Example m.add(draw_control) + circle = Circle(location=(50, 352), radius=100000, color="blue") + m.add(circle) + + editable_circle = Circle(location=(50, 356), radius=100000, pm_ignore=False, color="red") + m.add(editable_circle) + m Methods diff --git a/docs/layers/index.rst b/docs/layers/index.rst index d205566d..3aef888b 100644 --- a/docs/layers/index.rst +++ b/docs/layers/index.rst @@ -1,3 +1,5 @@ +.. _layers-section: + Layers ====== From 4b5db1ab812a63513e317926efe779209bea5d27 Mon Sep 17 00:00:00 2001 From: Riccardo Porreca Date: Mon, 22 Jul 2024 16:39:56 +0200 Subject: [PATCH 4/4] Use circle and disable circlemarker in GeomanDrawControl example * This is more sensible and aligned with the other examples. --- docs/controls/geoman_draw_control.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/controls/geoman_draw_control.rst b/docs/controls/geoman_draw_control.rst index 7d50b6b5..38a78dbd 100644 --- a/docs/controls/geoman_draw_control.rst +++ b/docs/controls/geoman_draw_control.rst @@ -51,13 +51,14 @@ Example "fillOpacity": 1.0 } } - draw_control.circlemarker = { + draw_control.circle = { "pathOptions": { "fillColor": "#efed69", "color": "#efed69", "fillOpacity": 0.62 } } + draw_control.circlemarker = {} draw_control.rectangle = { "pathOptions": { "fillColor": "#fca45d",