Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Leaflet-Geoman ignore created layers by default #1220

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Comment on lines +2 to +4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines in seem unrelated to the commit they are in.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, these two minor changes came when I rendered the fix to the list locally, since my IDE drops trailing spaces and there was a warning in Sphinx about the nr of = that I took the chance of fixing.

I should probably have at least added an additional line in the commit message stating stg like "Also fix some minor cosmetic RST formatting."

If you prefer to have a more accurate commit history, I am happy to force-push them as individual changes. Let me know, no big deal for me.

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