Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw should not interfere with dragPan.disable() #1191

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 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,8 @@ DirectSelect.onSetup = function(opts) {
dragMoveLocation: opts.startPos || null,
dragMoving: false,
canDragMove: false,
selectedCoordPaths: opts.coordPath ? [opts.coordPath] : []
selectedCoordPaths: opts.coordPath ? [opts.coordPath] : [],
desiredDragPanState: null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: probably this is some leftover variable?

};

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 @@ -204,6 +207,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 @@ -64,10 +64,14 @@ export default function(ctx) {

if (ctx.options.boxSelect) {
map.boxZoom.disable();
const dragPanState = map.dragPan.isEnabled();
Copy link
Contributor

@stepankuzmin stepankuzmin Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe it's worth renaming using isEnabled instead of state?

Suggested change
const dragPanState = map.dragPan.isEnabled();
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 (!dragPanState) {
map.dragPan.disable();
}
}

if (map.loaded()) {
Expand Down