Skip to content

Commit

Permalink
Make Leaflet-Geoman ignore created layers by default (#1220)
Browse files Browse the repository at this point in the history
* Make Leaflet-Geoman ignore created layers by default, fixes #1215

* Fix existing Geoman documentation list, not rendered as such

* Document `pm_ignore=False` in Geoman Draw Control documentation page

* Use circle and disable circlemarker in GeomanDrawControl example

* This is more sensible and aligned with the other examples.
  • Loading branch information
riccardoporreca authored Dec 5, 2024
1 parent 3551b13 commit 7f7343d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
19 changes: 15 additions & 4 deletions docs/controls/geoman_draw_control.rst
Original file line number Diff line number Diff line change
@@ -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 <https://geoman.io/>`_.

The following shapes are supported:

- marker
- circlemarker
- circle
Expand All @@ -24,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 <https://www.geoman.io/docs/modes/draw-mode#customize-style>`_ 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)

Expand All @@ -47,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",
Expand All @@ -64,6 +69,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
Expand Down
2 changes: 2 additions & 0 deletions docs/layers/index.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _layers-section:

Layers
======

Expand Down
4 changes: 4 additions & 0 deletions python/ipyleaflet/ipyleaflet/leaflet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down

0 comments on commit 7f7343d

Please sign in to comment.