Skip to content

Commit 0d091e1

Browse files
committed
When clicking an inactive feature in direct_select, select it
With this, you don't have to click twice to select another feature when you are in direct_select. The mode will still be changed to simple_select. So if you want to activate direct_select for another feature, you have to click it twice, but that's still one less click than before.
1 parent 405e3bf commit 0d091e1

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/modes/direct_select.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ DirectSelect.clickNoTarget = function () {
9898
this.changeMode(Constants.modes.SIMPLE_SELECT);
9999
};
100100

101-
DirectSelect.clickInactive = function () {
102-
this.changeMode(Constants.modes.SIMPLE_SELECT);
101+
DirectSelect.clickInactive = function (state, e) {
102+
const featureId = e.featureTarget.properties.id;
103+
this.changeMode(Constants.modes.SIMPLE_SELECT, { featureIds: [featureId] });
103104
};
104105

105106
DirectSelect.clickActiveFeature = function (state) {
@@ -181,11 +182,11 @@ DirectSelect.onTrash = function(state) {
181182

182183
DirectSelect.onMouseMove = function(state, e) {
183184
// On mousemove that is not a drag, stop vertex movement.
184-
const isFeature = isActiveFeature(e);
185185
const onVertex = isVertex(e);
186186
const noCoords = state.selectedCoordPaths.length === 0;
187-
if (isFeature && noCoords) this.updateUIClasses({ mouse: Constants.cursors.MOVE });
187+
if (isActiveFeature(e) && noCoords) this.updateUIClasses({ mouse: Constants.cursors.MOVE });
188188
else if (onVertex && !noCoords) this.updateUIClasses({ mouse: Constants.cursors.MOVE });
189+
else if (isInactiveFeature(e)) this.updateUIClasses({ mouse: Constants.cursors.POINTER });
189190
else this.updateUIClasses({ mouse: Constants.cursors.NONE });
190191
this.stopDragging(state);
191192

test/direct_select.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,22 @@ test('direct_select', (t) => {
273273
});
274274
});
275275

276+
t.test('direct_select - clicking an inactive feature should select it', (st) => {
277+
const [lineId] = Draw.add(getGeoJSON('line'));
278+
const [polygonId] = Draw.add(getGeoJSON('polygon'));
279+
Draw.changeMode(Constants.modes.DIRECT_SELECT, {
280+
featureId: lineId
281+
});
282+
const clickAt = getGeoJSON('polygon').geometry.coordinates[0][0];
283+
afterNextRender(() => {
284+
click(map, makeMouseEvent(clickAt[0], clickAt[1]));
285+
afterNextRender(() => {
286+
t.equal(Draw.getSelectedIds().indexOf(polygonId) !== -1, true, 'polygon is now selected');
287+
cleanUp(() => st.end());
288+
});
289+
});
290+
});
291+
276292
document.body.removeChild(mapContainer);
277293
t.end();
278294
});

0 commit comments

Comments
 (0)