Skip to content

Commit

Permalink
Prevent bearing snap on map.stop() (#9884)
Browse files Browse the repository at this point in the history
  • Loading branch information
andycalder authored Aug 4, 2020
1 parent a85e997 commit ebb80aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/ui/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ class Camera extends Evented {
}
if (!allowGestures) {
const handlers = (this: any).handlers;
if (handlers) handlers.stop();
if (handlers) handlers.stop(false);
}
return this;
}
Expand Down
20 changes: 8 additions & 12 deletions src/ui/handler_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ class HandlerManager {
_updatingCamera: boolean;
_changes: Array<[HandlerResult, Object, any]>;
_previousActiveHandlers: { [string]: Handler };
_bearingChanged: boolean;
_listeners: Array<[HTMLElement, string, void | {passive?: boolean, capture?: boolean}]>;

constructor(map: Map, options: { interactive: boolean, pitchWithRotate: boolean, clickTolerance: number, bearingSnap: number}) {
Expand Down Expand Up @@ -235,15 +234,15 @@ class HandlerManager {
this._handlersById[handlerName] = handler;
}

stop() {
stop(allowEndAnimation: boolean) {
// do nothing if this method was triggered by a gesture update
if (this._updatingCamera) return;

for (const {handler} of this._handlers) {
handler.reset();
}
this._inertia.clear();
this._fireEvents({}, {});
this._fireEvents({}, {}, allowEndAnimation);
this._changes = [];
}

Expand Down Expand Up @@ -293,7 +292,7 @@ class HandlerManager {
handleEvent(e: InputEvent | RenderFrameEvent, eventName?: string) {

if (e.type === 'blur') {
this.stop();
this.stop(true);
return;
}

Expand Down Expand Up @@ -358,7 +357,7 @@ class HandlerManager {
const {cameraAnimation} = mergedHandlerResult;
if (cameraAnimation) {
this._inertia.clear();
this._fireEvents({}, {});
this._fireEvents({}, {}, true);
this._changes = [];
cameraAnimation(this._map);
}
Expand Down Expand Up @@ -416,7 +415,7 @@ class HandlerManager {
const tr = map.transform;

if (!hasChange(combinedResult)) {
return this._fireEvents(combinedEventsInProgress, deactivatedHandlers);
return this._fireEvents(combinedEventsInProgress, deactivatedHandlers, true);
}

let {panDelta, zoomDelta, bearingDelta, pitchDelta, around, pinchAround} = combinedResult;
Expand All @@ -437,11 +436,11 @@ class HandlerManager {

this._map._update();
if (!combinedResult.noInertia) this._inertia.record(combinedResult);
this._fireEvents(combinedEventsInProgress, deactivatedHandlers);
this._fireEvents(combinedEventsInProgress, deactivatedHandlers, true);

}

_fireEvents(newEventsInProgress: { [string]: Object }, deactivatedHandlers: Object) {
_fireEvents(newEventsInProgress: { [string]: Object }, deactivatedHandlers: Object, allowEndAnimation: boolean) {

const wasMoving = isMoving(this._eventsInProgress);
const nowMoving = isMoving(newEventsInProgress);
Expand All @@ -465,8 +464,6 @@ class HandlerManager {
this._fireEvent(name, startEvents[name]);
}

if (newEventsInProgress.rotate) this._bearingChanged = true;

if (nowMoving) {
this._fireEvent('move', nowMoving.originalEvent);
}
Expand All @@ -493,7 +490,7 @@ class HandlerManager {
}

const stillMoving = isMoving(this._eventsInProgress);
if ((wasMoving || nowMoving) && !stillMoving) {
if (allowEndAnimation && (wasMoving || nowMoving) && !stillMoving) {
this._updatingCamera = true;
const inertialEase = this._inertia._onMoveEnd(this._map.dragPan._inertiaOptions);

Expand All @@ -510,7 +507,6 @@ class HandlerManager {
this._map.resetNorth();
}
}
this._bearingChanged = false;
this._updatingCamera = false;
}

Expand Down

0 comments on commit ebb80aa

Please sign in to comment.