Skip to content

Commit

Permalink
Draw should not interfere with dragPan.disable() (#1216)
Browse files Browse the repository at this point in the history
* #654 retaining dragPan state for simple_select, direct_select, and setup

* #654 further limiting direct_select to only re-enable dragPan when direct_select has disabled it

* #654 further limiting simple_select to only re-enable dragPan when direct_select has disabled it

* refactor: applied suggestions

---------

Co-authored-by: holyblader2010 <[email protected]>
Co-authored-by: Stepan Kuzmin <[email protected]>
  • Loading branch information
3 people authored Jul 1, 2024
1 parent 5baf476 commit 3802950
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/modes/direct_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ DirectSelect.fireActionable = function(state) {
};

DirectSelect.startDragging = function(state, e) {
state.initialDragPanState = this.map.dragPan.isEnabled();

this.map.dragPan.disable();
state.canDragMove = true;
state.dragMoveLocation = e.lngLat;
};

DirectSelect.stopDragging = function(state) {
this.map.dragPan.enable();
if (state.canDragMove && state.initialDragPanState === true) {
this.map.dragPan.enable();
}
state.dragMoving = false;
state.canDragMove = false;
state.dragMoveLocation = null;
Expand Down Expand Up @@ -128,7 +132,7 @@ DirectSelect.onSetup = function(opts) {
dragMoveLocation: opts.startPos || null,
dragMoving: false,
canDragMove: false,
selectedCoordPaths: opts.coordPath ? [opts.coordPath] : []
selectedCoordPaths: opts.coordPath ? [opts.coordPath] : [],
};

this.setSelectedCoordinates(this.pathsToCoordinates(featureId, state.selectedCoordPaths));
Expand Down
6 changes: 5 additions & 1 deletion src/modes/simple_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SimpleSelect.onSetup = function(opts) {
canBoxSelect: false,
dragMoving: false,
canDragMove: false,
initialDragPanState: this.map.dragPan.isEnabled(),
initiallySelectedFeatureIds: opts.featureIds || []
};

Expand Down Expand Up @@ -85,7 +86,9 @@ SimpleSelect.stopExtendedInteractions = function(state) {
state.boxSelectElement = null;
}

this.map.dragPan.enable();
if ((state.canDragMove || state.canBoxSelect) && state.initialDragPanState === true) {
this.map.dragPan.enable();
}

state.boxSelecting = false;
state.canBoxSelect = false;
Expand Down Expand Up @@ -207,6 +210,7 @@ SimpleSelect.clickOnFeature = function(state, e) {
};

SimpleSelect.onMouseDown = function(state, e) {
state.initialDragPanState = this.map.dragPan.isEnabled();
if (CommonSelectors.isActiveFeature(e)) return this.startOnActiveFeature(state, e);
if (this.drawConfig.boxSelect && CommonSelectors.isShiftMousedown(e)) return this.startBoxSelect(state, e);
};
Expand Down
4 changes: 4 additions & 0 deletions src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ export default function(ctx) {
if (ctx.options.boxSelect) {
ctx.boxZoomInitial = map.boxZoom.isEnabled();
map.boxZoom.disable();
const dragPanIsEnabled = map.dragPan.isEnabled();
// Need to toggle dragPan on and off or else first
// dragPan disable attempt in simple_select doesn't work
map.dragPan.disable();
map.dragPan.enable();
if (!dragPanIsEnabled) {
map.dragPan.disable();
}
}

if (map.loaded()) {
Expand Down

0 comments on commit 3802950

Please sign in to comment.