Skip to content

Commit

Permalink
fix(draw): recreate modify interaction instead of de/-activating
Browse files Browse the repository at this point in the history
this prevents once edited feature geometries to stay editable when another feature geometry should only be editable
  • Loading branch information
tkohr committed Sep 27, 2024
1 parent 3f7f77b commit f82feaf
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/composables/draw/edit.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand All @@ -31,9 +32,9 @@ export default function useEdit() {

watch(editStateActive, editStateActive => {
if (editStateActive) {
modifyInteraction.setActive(true)
createModifyInteraction()
} else {
modifyInteraction.setActive(false)
map.removeInteraction(modifyInteraction)
}
})

Expand Down Expand Up @@ -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)
})
}
}

0 comments on commit f82feaf

Please sign in to comment.