Skip to content
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

Allow deleting the whole feature from direct_select #975

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
25 changes: 15 additions & 10 deletions src/modes/direct_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,23 @@ DirectSelect.toDisplayFeatures = function(state, geojson, push) {
};

DirectSelect.onTrash = function(state) {
// Uses number-aware sorting to make sure '9' < '10'. Comparison is reversed because we want them
// in reverse order so that we can remove by index safely.
state.selectedCoordPaths
.sort((a, b) => b.localeCompare(a, 'en', { numeric: true }))
.forEach(id => state.feature.removeCoordinate(id));
this.fireUpdate();
state.selectedCoordPaths = [];
this.clearSelectedCoordinates();
this.fireActionable(state);
if (state.feature.isValid() === false) {
if (state.selectedCoordPaths.length === 0) {
this.deleteFeature([state.featureId]);
this.changeMode(Constants.modes.SIMPLE_SELECT, {});
} else {
// Uses number-aware sorting to make sure '9' < '10'. Comparison is reversed because we want them
// in reverse order so that we can remove by index safely.
state.selectedCoordPaths
.sort((a, b) => b.localeCompare(a, 'en', { numeric: true }))
.forEach(id => state.feature.removeCoordinate(id));
this.fireUpdate();
state.selectedCoordPaths = [];
this.clearSelectedCoordinates();
this.fireActionable(state);
if (state.feature.isValid() === false) {
this.deleteFeature([state.featureId]);
this.changeMode(Constants.modes.SIMPLE_SELECT, {});
}
}
};

Expand Down
13 changes: 13 additions & 0 deletions test/direct_select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ test('direct_select', (t) => {
});
});

t.test('direct_select - trashing with no vertices selected should delete the feature', (st) => {
const ids = Draw.add(getGeoJSON('polygon'));
Draw.changeMode(Constants.modes.DIRECT_SELECT, {
featureId: ids[0]
});
afterNextRender(() => {
Draw.trash();
const afterTrash = Draw.get(ids[0]);
st.equal(afterTrash, undefined);
cleanUp(() => st.end());
});
});

t.test('direct_select - a click on a vertex and than dragging the map shouldn\'t drag the vertex', (st) => {
const ids = Draw.add(getGeoJSON('polygon'));
Draw.changeMode(Constants.modes.DIRECT_SELECT, {
Expand Down