From 249db35125c89a5b7ffb2c4a5337b828150abe49 Mon Sep 17 00:00:00 2001 From: holyblader2010 Date: Wed, 4 Oct 2017 14:34:56 -0500 Subject: [PATCH] #654 retaining dragPan state for simple_select, direct_select, and setup --- src/modes/direct_select.js | 9 +++++++-- src/modes/simple_select.js | 6 +++++- src/setup.js | 4 ++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/modes/direct_select.js b/src/modes/direct_select.js index d4771cd8f..71cce0312 100644 --- a/src/modes/direct_select.js +++ b/src/modes/direct_select.js @@ -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; @@ -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)); diff --git a/src/modes/simple_select.js b/src/modes/simple_select.js index 9920ae327..f3e9b9d2e 100644 --- a/src/modes/simple_select.js +++ b/src/modes/simple_select.js @@ -18,6 +18,7 @@ SimpleSelect.onSetup = function(opts) { canBoxSelect: false, dragMoveing: false, canDragMove: false, + initialDragPanState: this.map.dragPan.isEnabled(), initiallySelectedFeatureIds: opts.featureIds || [] }; @@ -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; @@ -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); }; diff --git a/src/setup.js b/src/setup.js index cee39abd4..f396be815 100644 --- a/src/setup.js +++ b/src/setup.js @@ -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;