Skip to content

fix: prevent removing corner of a rectangle when lockRectangles is used #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions modules/editable-layers/src/edit-modes/modify-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,31 @@ export class ModifyMode extends GeoJsonEditMode {
if (pickedExistingHandle) {
const {featureIndex, positionIndexes} = pickedExistingHandle.properties;

let updatedData;
try {
updatedData = new ImmutableFeatureCollection(props.data)
.removePosition(featureIndex, positionIndexes)
.getObject();
} catch (ignored) {
// This happens if user attempts to remove the last point
}
const feature = props.data.features[featureIndex];
const canRemovePosition = !(
props.modeConfig?.lockRectangles && feature?.properties.shape === 'Rectangle'
);
if (canRemovePosition) {
let updatedData;
try {
updatedData = new ImmutableFeatureCollection(props.data)
.removePosition(featureIndex, positionIndexes)
.getObject();
} catch (ignored) {
// This happens if user attempts to remove the last point
}

if (updatedData) {
props.onEdit({
updatedData,
editType: 'removePosition',
editContext: {
featureIndexes: [featureIndex],
positionIndexes,
position: pickedExistingHandle.geometry.coordinates
}
});
if (updatedData) {
props.onEdit({
updatedData,
editType: 'removePosition',
editContext: {
featureIndexes: [featureIndex],
positionIndexes,
position: pickedExistingHandle.geometry.coordinates
}
});
}
}
} else if (pickedIntermediateHandle) {
const {featureIndex, positionIndexes} = pickedIntermediateHandle.properties;
Expand Down
Loading