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
3 changes: 2 additions & 1 deletion src/modes/direct_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ DirectSelect.onSetup = function(opts) {
return state;
};

DirectSelect.onStop = function() {
DirectSelect.onStop = function(state) {
doubleClickZoom.enable(this);
this.clearSelectedCoordinates();
this.stopDragging(state);
};

DirectSelect.toDisplayFeatures = function(state, geojson, push) {
Expand Down
27 changes: 27 additions & 0 deletions test/direct_select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,32 @@ test('direct_select', async (t) => {
await cleanUp();
});

await t.test('direct_select - stopping mode mid-drag should reset the plugin state', async () => {
map.dragPan.enable();

const [polygonId] = Draw.add(getGeoJSON('polygon'));
Draw.changeMode(Constants.modes.DIRECT_SELECT, {
featureId: polygonId
});

const originalPolygon = getGeoJSON('polygon');
const centroid = turfCentroid(originalPolygon).geometry.coordinates;
await afterNextRender();

assert.equal(map.dragPan.isEnabled(), true, 'dragPan should be enabled initially');

map.fire('mousedown', makeMouseEvent(centroid[0], centroid[1]));
map.fire('mousemove', makeMouseEvent(centroid[0] + 15, centroid[1] + 15, { buttons: 1 }));

assert.equal(map.dragPan.isEnabled(), false, 'dragPan should be disabled during drag');

Draw.changeMode(Constants.modes.SIMPLE_SELECT);
await afterNextRender();

assert.equal(map.dragPan.isEnabled(), true, 'dragPan should be re-enabled after stopping mode');

await cleanUp();
});

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