Skip to content

Commit

Permalink
Merge pull mapbox#1216 - avoid interfering with dragPan
Browse files Browse the repository at this point in the history
  • Loading branch information
axekan committed Jun 24, 2024
1 parent d876e82 commit f433c3e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/modes/direct_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ 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
7 changes: 5 additions & 2 deletions 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 @@ -164,7 +167,6 @@ SimpleSelect.startOnActiveFeature = function(state, e) {
};

SimpleSelect.clickOnFeature = function(state, e) {
if (e.defaultPrevented) return;
// Stop everything
doubleClickZoom.disable(this);
this.stopExtendedInteractions(state);
Expand Down Expand Up @@ -208,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 @@ -66,10 +66,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 f433c3e

Please sign in to comment.