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

DrawControl edited event: which shape was edited? #849

Open
sradomski opened this issue Jun 28, 2021 · 4 comments
Open

DrawControl edited event: which shape was edited? #849

sradomski opened this issue Jun 28, 2021 · 4 comments

Comments

@sradomski
Copy link

Hey there,

as far as I can see the DrawControl will only store the last_action and the last_drawn geometry in the Python representation on the server side, whereas last_draw is also set prior to sending the delete action. This allows to keep track about the created and delete geometries.

However, I can not figure out how to know, which geometry was edited, when receiving the respective event. I do know the new geometry after the changes from last_draw, but I do not know the original geometry that was edited, which makes it impossible to know the shape of geometries currently on the map.

Am I missing something or is this functionality not implemented?
Stefan

@giswqs
Copy link
Contributor

giswqs commented Jun 28, 2021

As far as I know, ipyleaflet does not support this yet. See a relevant issue #672

@sradomski
Copy link
Author

sradomski commented Jun 28, 2021

First of all, thank you for your answer!

Yes, that issue is related and if it were solved, getting the edited and the original shape would not be necessary to keep track as you could just list all shapes.

So there is currently no way of knowing the set of shapes that were established with the DrawControl widget when shape editing is enabled? Because one is supposed to keep track of shapes via the on_draw handler but the edited event only carries information about the new shape, not the original one that was changed, making it impossible to keep track.

Is there some way to "hack" it? I tried to change the various objects in self when on_draw is called (e.g. last_draw) but changes would not be persisted, nor was it possible to introduce any kind of dynamic shape identifiers in the GeoJSON properties via draw_handler.polygon['shapeOptions'].

@giswqs
Copy link
Contributor

giswqs commented Jan 30, 2022

I was able to hack it to keep track of the edited geometries. You can inspect the leafmap source code to see how I implemented it. All geometries are stored in draw_control.data as a list of features. Whenever a feature is edited, the draw_control.data is updated. The challenging part is that draw_control.data is not updated within the on_draw handler. It is only updated once the program gets out of the on_draw handler. So you will need something else outside the on_draw handler to figure out the edited geometries.

Some relevant source in leafmap that handles this:

Notebook: https://leafmap.org/notebooks/46_edit_vector/

Demo:

46_edit_vector.mp4

@0x000eHx
Copy link

Did someone find an ipyleaflet/ipywidget event which gets called after on_draw, meaning the the DrawControl.data property is updated by then?
It's weird to access DrawControl.data within another methode for finally accepting all drawn geometries, if keeping track of all geometries/markers could get updated with every change (on its own). But on_draw sadly doesn't do the trick...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants