Skip to content
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
9 changes: 5 additions & 4 deletions src/modes/direct_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ DirectSelect.clickNoTarget = function () {
this.changeMode(Constants.modes.SIMPLE_SELECT);
};

DirectSelect.clickInactive = function () {
this.changeMode(Constants.modes.SIMPLE_SELECT);
DirectSelect.clickInactive = function (state, e) {
const featureId = e.featureTarget.properties.id;
this.changeMode(Constants.modes.SIMPLE_SELECT, { featureIds: [featureId] });
};

DirectSelect.clickActiveFeature = function (state) {
Expand Down Expand Up @@ -181,11 +182,11 @@ DirectSelect.onTrash = function(state) {

DirectSelect.onMouseMove = function(state, e) {
// On mousemove that is not a drag, stop vertex movement.
const isFeature = isActiveFeature(e);
const onVertex = isVertex(e);
const noCoords = state.selectedCoordPaths.length === 0;
if (isFeature && noCoords) this.updateUIClasses({ mouse: Constants.cursors.MOVE });
if (isActiveFeature(e) && noCoords) this.updateUIClasses({ mouse: Constants.cursors.MOVE });
else if (onVertex && !noCoords) this.updateUIClasses({ mouse: Constants.cursors.MOVE });
else if (isInactiveFeature(e)) this.updateUIClasses({ mouse: Constants.cursors.POINTER });
else this.updateUIClasses({ mouse: Constants.cursors.NONE });
this.stopDragging(state);

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

t.test('direct_select - clicking an inactive feature should select it', (st) => {
const [lineId] = Draw.add(getGeoJSON('line'));
const [polygonId] = Draw.add(getGeoJSON('polygon'));
Draw.changeMode(Constants.modes.DIRECT_SELECT, {
featureId: lineId
});
const clickAt = getGeoJSON('polygon').geometry.coordinates[0][0];
afterNextRender(() => {
click(map, makeMouseEvent(clickAt[0], clickAt[1]));
map.fire.resetHistory();
afterNextRender(() => {
const args = getFireArgs().filter(arg => arg[0] === 'draw.selectionchange');
t.equal(args.length, 1, 'should have one and only one selectionchange event');
t.equal(Draw.getSelectedIds().indexOf(polygonId) !== -1, true, 'polygon is now selected');
cleanUp(() => st.end());
});
});
});

document.body.removeChild(mapContainer);
t.end();
});