Skip to content

GeomanDrawControl's on_draw method doesn't trigger when a shape is edited. #1243

Open
@hydro-scope

Description

@hydro-scope

Hi,

I would like to begin by thanking you for your library which opens up a great many possibilities.

However, I have experienced some issues when trying to edit Layers (markers and polygons in my case) with the edit tools GeomanDrawControl provides.

When I load the shapes programatically and then press the "Edit Layers" button, I am able to change the shapes and add nodes to the polygons as well as move the markers around. But, once I press finish on the "Edit Layers" button, I would have expected this to trigger a leaflet event, that would have been recognised by the _handle_leaflet_event method of GeomanDrawControl :

def _handle_leaflet_event(self, _, content, buffers):
if content.get('event', '').startswith('pm:'):
action = content.get('event').split(':')[1]
geo_json = content.get('geo_json')
if action == "vertexadded":
self._draw_callbacks(self, action=action, geo_json=geo_json)
return
# Some actions return only new feature, while others return all features
# in the layer
if not isinstance(geo_json, list):
geo_json = [geo_json]
self._draw_callbacks(self, action=action, geo_json=geo_json)

which in turn would trigger the _draw_callbacks specified using the òn_draw`method :

https://github.com/jupyter-widgets/ipyleaflet/blob/7f7343d5595b2e9868885706522890cae98fef47/python/ipyleaflet/ipyleaflet/leaflet.py#L2347C5-L2357C72

But when I print the content argument _handle_leaflet_event when using the edit mode it seems that nothing is received by _handle_leaflet_event, whereas when I use draw commands the content dict prints after each newly created layer.

So my question is whether this is intended, or if perhaps it would make sense to have Geoman to broadcast messages (specifically pm:update messages documented here) as I understand it is done for pm:createmessages in the following lines :

this.map_view.obj.on(
'pm:create',
(e: { shape: L.PM.SUPPORTED_SHAPES; layer: LayerShapes }) => {
var layer = e.layer;
this.send({
event: 'pm:create',
geo_json: this.layer_to_json(layer),
});

Being a pure python dev, I'm not too familiar with js syntax, but if someone can confirm that I'm looking in the right direction, and that this could be a feature, I could potentially prepare a PR to fix this.

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions