Skip to content

Commit

Permalink
Ensure DragRotate stops when the window looses focus. Fixes mapbox#3389
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewharvey committed Mar 9, 2017
1 parent 8080a07 commit 7af2dbd
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/ui/handler/drag_rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class DragRotateHandler {
util.bindAll([
'_onDown',
'_onMove',
'_onUp'
'_onUp',
'_onBlur'
], this);

}
Expand Down Expand Up @@ -82,6 +83,7 @@ class DragRotateHandler {

window.document.addEventListener('mousemove', this._onMove);
window.document.addEventListener('mouseup', this._onUp);
window.addEventListener('blur', this._onBlur);

this._active = false;
this._inertia = [[Date.now(), this._map.getBearing()]];
Expand All @@ -91,6 +93,14 @@ class DragRotateHandler {
e.preventDefault();
}

/**
* Deactivates DragRotate when the window looses focus. Otherwise the mouseup event is never fired and when the
* window comes back in focus DragRotate is still active even though the mouse isn't down.
*/
_onBlur(e) {
this._onUp(e);
}

_onMove(e) {
if (this._ignoreEvent(e)) return;

Expand Down Expand Up @@ -129,6 +139,7 @@ class DragRotateHandler {
if (this._ignoreEvent(e)) return;
window.document.removeEventListener('mousemove', this._onMove);
window.document.removeEventListener('mouseup', this._onUp);
window.removeEventListener('blur', this._onBlur);

if (!this.isActive()) return;

Expand Down

0 comments on commit 7af2dbd

Please sign in to comment.