Skip to content

Commit

Permalink
PB-199: Remove last point on right click on modify mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsunni committed Nov 20, 2024
1 parent d5d7ed0 commit 12f2a3d
Showing 1 changed file with 36 additions and 22 deletions.
58 changes: 36 additions & 22 deletions src/modules/drawing/components/useModifyInteraction.composable.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export default function useModifyInteraction(features) {
continueDrawingInteraction.setActive(true)
modifyInteraction.setActive(false)
olMap.on('contextmenu', onMapRightClick)
} else if (newValue === EditMode.MODIFY) {
modifyInteraction.setActive(true)
continueDrawingInteraction.setActive(false)
olMap.on('contextmenu', onMapRightClick) // Keep right-click listener
} else {
modifyInteraction.setActive(true)
continueDrawingInteraction.setActive(false)
Expand Down Expand Up @@ -108,7 +112,20 @@ export default function useModifyInteraction(features) {
})

function onMapRightClick(_event) {
continueDrawingInteraction.removeLastPoint()
if (continueDrawingInteraction.getActive()) {
continueDrawingInteraction.removeLastPoint()
} else if (modifyInteraction.getActive() && features.getArray().length > 0) {
const feature = features.getArray()[0]
const geometry = feature.getGeometry()
const coordinates = geometry.getCoordinates()
if (coordinates.length > 2) {
// Keep at least 2 points
coordinates.pop()
geometry.setCoordinates(coordinates)
}
// Updating the store feature
updateStoreFeatureCoordinatesGeometry(feature)
}
}

function onModifyStart(event) {
Expand Down Expand Up @@ -138,16 +155,7 @@ export default function useModifyInteraction(features) {
isDragged: false,
...dispatcher,
})
store.dispatch('changeFeatureCoordinates', {
feature: storeFeature,
coordinates: extractOlFeatureCoordinates(feature),
geodesicCoordinates: extractOlFeatureGeodesicCoordinates(feature),
...dispatcher,
})
store.dispatch('changeFeatureGeometry', {
feature: storeFeature,
geometry: new GeoJSON().writeGeometryObject(feature.getGeometry()),
})
updateStoreFeatureCoordinatesGeometry(feature)
olMap.getTarget().classList.remove(cursorGrabbingClass)
debounceSaveDrawing()
}
Expand All @@ -158,19 +166,25 @@ export default function useModifyInteraction(features) {
const feature = event.feature
// Update the original feature with new coordinates
if (feature) {
const storeFeature = feature.get('editableFeature')
store.dispatch('changeFeatureCoordinates', {
feature: storeFeature,
coordinates: extractOlFeatureCoordinates(feature),
geodesicCoordinates: extractOlFeatureGeodesicCoordinates(feature),
...dispatcher,
})
store.dispatch('changeFeatureGeometry', {
feature: storeFeature,
geometry: new GeoJSON().writeGeometryObject(feature.getGeometry()),
})
updateStoreFeatureCoordinatesGeometry(feature)
store.dispatch('setEditingMode', { mode: EditMode.MODIFY, ...dispatcher })
debounceSaveDrawing()
}
}

// Update the store feature with the new coordinates and geometry
function updateStoreFeatureCoordinatesGeometry(feature) {
const storeFeature = feature.get('editableFeature')
store.dispatch('changeFeatureCoordinates', {
feature: storeFeature,
coordinates: extractOlFeatureCoordinates(feature),
geodesicCoordinates: extractOlFeatureGeodesicCoordinates(feature),
...dispatcher,
})
store.dispatch('changeFeatureGeometry', {
feature: storeFeature,
geometry: new GeoJSON().writeGeometryObject(feature.getGeometry()),
...dispatcher,
})
}
}

0 comments on commit 12f2a3d

Please sign in to comment.