leaflet-geoman icon indicating copy to clipboard operation
leaflet-geoman copied to clipboard

Update edit handles when the layer is updated programmatically

Open haoliangyu opened this issue 7 years ago β€’ 5 comments

In my use case, layers are edited both interactively and programmatically.

When a layer is at edit mode and is updated programmatically, the edit handles are not moved accordingly. The result is like this:

screenshot from 2018-06-30 11-43-04

A workaround is to toggle off and on the layer editing to recreate the handles:

// destroy old handles
polygon.pm.toggleEdit();
// create new handles with current coordinates
polygon.pm.toggleEdit();

It would be nice to have the handles updated automatically, since leaflet.pm has been listening to the layer changes. You can see a full demo at this plunker example.

haoliangyu avatar Jun 30 '18 15:06 haoliangyu

πŸ‘ thanks for the demo. Good addition, I will address this!

codeofsumit avatar Jun 30 '18 16:06 codeofsumit

Took a look - I asked @perliedman for help on this: https://twitter.com/TweetsOfSumit/status/1013355361573789696

I did not find a possibility to listen to changes done via leaflets setLatLngs yet πŸ€”. The PR/Branch is here: https://github.com/codeofsumit/leaflet.pm/pull/309

I've added the failing Cypress test for this usecase.

codeofsumit avatar Jul 01 '18 09:07 codeofsumit

seems like there is no event in leaflet to catch this. I've raised a feature request with leaflet: https://github.com/Leaflet/Leaflet/issues/6214 Let's see what they say - if they include it I would like to wait for this. If not, I would try to create a workaround if there is one that is not that dirty.

In the meantime, you can use polygon.pm.enable(); instead of toggling edit mode twice.

polygon.setLatLngs([[0, 0],[0, 20],[20, 20],[20, 0]]);
polygon.pm.enable();

Calling enable again will simply update everything (you could pass new options too).

codeofsumit avatar Jul 02 '18 18:07 codeofsumit

The feature request for Leaflet is this now: https://github.com/Leaflet/Leaflet/issues/2235

codeofsumit avatar Jul 18 '18 10:07 codeofsumit

Created PR https://github.com/Leaflet/Leaflet/pull/7150

Falke-Design avatar May 16 '20 17:05 Falke-Design