diff --git a/src/modes/direct_select.js b/src/modes/direct_select.js index a9118c8dd..136517017 100644 --- a/src/modes/direct_select.js +++ b/src/modes/direct_select.js @@ -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; @@ -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)); diff --git a/src/modes/simple_select.js b/src/modes/simple_select.js index 2b2804e0f..de3f6c370 100644 --- a/src/modes/simple_select.js +++ b/src/modes/simple_select.js @@ -18,6 +18,7 @@ SimpleSelect.onSetup = function(opts) { canBoxSelect: false, dragMoving: false, canDragMove: false, + initialDragPanState: this.map.dragPan.isEnabled(), initiallySelectedFeatureIds: opts.featureIds || [] }; @@ -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; @@ -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); }; diff --git a/src/setup.js b/src/setup.js index 6e553a473..e1524db82 100644 --- a/src/setup.js +++ b/src/setup.js @@ -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()) {