Update vertices in draw mode
brunstruts opened this issue · comments
I'm trying to programatically change the latlngs of a shape while drawing it. I am using setLatLngs() on the workingLayer and that works for the line of the shape, but the vertices stays put.
Is there a method for updating the vertices to align with the latlngs?
I have tried enabling drawing and the layer, as proposed in #914, but this only works in edit mode, not drawing mode.
Geoman doesn't support this but maybe with this information you get the right way:
All the markers are stored in the layerGroup
and markers
, so you can remove all layers from this lists and then recreate all the markers again with _createMarker
leaflet-geoman/src/js/Draw/L.PM.Draw.Line.js
Lines 386 to 397 in 4254074
Also checkout the generation / redrawing of the markers in edit mode:
leaflet-geoman/src/js/Edit/L.PM.Edit.Line.js
Line 133 in 4254074
Thank you for the reply
I tried to clear all layers and set new markers (a lot like how it was done in _initMarkers()):
map.pm.Draw.Line._layerGroup.clearLayers();
map.pm.Draw.Line._layerGroup = new LayerGroup();
map.pm.Draw.Line._layerGroup._pmTempLayer = true;
map.pm.Draw.Line._markers = newCoords.map((latlng) => {
return map.pm.Draw.Line._createMarker(latlng);
});
map.addLayer(map.pm.Draw.Line._layerGroup);
And the marker was removed! But sadly the path got removed along with it. Updating the path with updatePath() did nothing either. Any more ideas?
I made it work!
while (map.pm.Draw.Line._markers.length > 1) {
map.pm.Draw.Line._removeLastVertex();
}
newCoords.forEach((latlng) => {
map.pm.Draw.Line._createVertex({latlng: latlng});
});
This works as long as I don't need the first vertex changed, which so far is not a condition.
Thanks for all the help!