From f82feaf61d7e0c32af3e183aa97e78ad917bb13f Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Fri, 27 Sep 2024 15:36:13 +0200 Subject: [PATCH] fix(draw): recreate modify interaction instead of de/-activating this prevents once edited feature geometries to stay editable when another feature geometry should only be editable --- src/composables/draw/edit.composable.ts | 35 ++++++++++++++----------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/composables/draw/edit.composable.ts b/src/composables/draw/edit.composable.ts index 36708e292..260ea568a 100644 --- a/src/composables/draw/edit.composable.ts +++ b/src/composables/draw/edit.composable.ts @@ -18,6 +18,7 @@ export default function useEdit() { ) const { updateDrawnFeature, setEditActiveState } = useDrawStore() + let modifyInteraction: Modify const map = useMap().getOlMap() const editSource = new VectorSource({ features: [] as DrawnFeature[], @@ -31,9 +32,9 @@ export default function useEdit() { watch(editStateActive, editStateActive => { if (editStateActive) { - modifyInteraction.setActive(true) + createModifyInteraction() } else { - modifyInteraction.setActive(false) + map.removeInteraction(modifyInteraction) } }) @@ -62,18 +63,22 @@ export default function useEdit() { } }) - const modifyInteraction = new Modify({ - source: editSource, - pixelTolerance: 20, - deleteCondition: function (event) { - return noModifierKeys(event) && singleClick(event) - }, - }) - modifyInteraction.setActive(false) - map.addInteraction(modifyInteraction) + function createModifyInteraction() { + if (modifyInteraction) { + map.removeInteraction(modifyInteraction) + } + modifyInteraction = new Modify({ + source: editSource, + pixelTolerance: 20, + deleteCondition: function (event) { + return noModifierKeys(event) && singleClick(event) + }, + }) + map.addInteraction(modifyInteraction) - listen(modifyInteraction, 'modifyend', event => { - const feature = (event as ModifyEvent).features.getArray()[0] - updateDrawnFeature(feature as DrawnFeature) - }) + listen(modifyInteraction, 'modifyend', event => { + const feature = (event as ModifyEvent).features.getArray()[0] + updateDrawnFeature(feature as DrawnFeature) + }) + } }