Skip to content

Commit

Permalink
mapbox#654 retaining dragPan state for simple_select, direct_select, …
Browse files Browse the repository at this point in the history
…and setup
  • Loading branch information
holyblader2010 committed Oct 4, 2017
1 parent 72e4705 commit 249db35
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/modes/direct_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,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.initialDragPanState) {
this.map.dragPan.enable();
}
state.dragMoving = false;
state.canDragMove = false;
state.dragMoveLocation = null;
Expand Down Expand Up @@ -129,7 +133,8 @@ DirectSelect.onSetup = function(opts) {
dragMoveLocation: opts.startPos || null,
dragMoving: false,
canDragMove: false,
selectedCoordPaths: opts.coordPath ? [opts.coordPath] : []
selectedCoordPaths: opts.coordPath ? [opts.coordPath] : [],
initialDragPanState: this.map.dragPan.isEnabled()
};

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,
dragMoveing: false,
canDragMove: false,
initialDragPanState: this.map.dragPan.isEnabled(),
initiallySelectedFeatureIds: opts.featureIds || []
};

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

this.map.dragPan.enable();
if (state.initialDragPanState !== false) {
this.map.dragPan.enable();
}

state.boxSelecting = false;
state.canBoxSelect = false;
Expand Down Expand Up @@ -205,6 +208,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 @@ -32,10 +32,14 @@ module.exports = function(ctx) {

if (ctx.options.boxSelect) {
map.boxZoom.disable();
const dragPanState = 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 (!dragPanState) {
map.dragPan.disable();
}
}

let intervalId = null;
Expand Down

0 comments on commit 249db35

Please sign in to comment.