From d28e51d9b49930b00cec246ca2780fa6332f12be Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 23 Feb 2018 15:13:18 -0800 Subject: [PATCH] Add comments --- src/ui/handler/drag_pan.js | 9 +++++++-- src/ui/handler/drag_rotate.js | 9 ++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/ui/handler/drag_pan.js b/src/ui/handler/drag_pan.js index 8d47b0e6f51..24dc9828f46 100644 --- a/src/ui/handler/drag_pan.js +++ b/src/ui/handler/drag_pan.js @@ -91,6 +91,11 @@ class DragPanHandler { if (this._map.dragRotate.isActive()) return; if (this.isActive()) return; + // Bind window-level event listeners for move and up/end events. In the absence of + // the pointer capture API, which is not supported by all necessary platforms, + // window-level event listeners give us the best shot at capturing events that + // fall outside the map canvas element. Use `{capture: true}` for the move event + // to prevent map move events from being fired during a drag. if (e.touches) { if ((e.touches: any).length > 1) return; window.document.addEventListener('touchmove', this._onMove, {capture: true}); @@ -101,8 +106,8 @@ class DragPanHandler { window.document.addEventListener('mouseup', this._onUp); } - // Deactivate DragPan when the window loses focus. Otherwise if a mouseup occurs when the window - // isn't in focus, DragPan will still be active even though the mouse is no longer pressed. + // Deactivate when the window loses focus. Otherwise if a mouseup occurs when the window + // isn't in focus, dragging will continue even though the mouse is no longer pressed. window.addEventListener('blur', this._onUp); this._active = false; diff --git a/src/ui/handler/drag_rotate.js b/src/ui/handler/drag_rotate.js index 8c3610e2287..c9b1530b8e0 100644 --- a/src/ui/handler/drag_rotate.js +++ b/src/ui/handler/drag_rotate.js @@ -118,9 +118,16 @@ class DragRotateHandler { DOM.disableDrag(); + // Bind window-level event listeners for move and up/end events. In the absence of + // the pointer capture API, which is not supported by all necessary platforms, + // window-level event listeners give us the best shot at capturing events that + // fall outside the map canvas element. Use `{capture: true}` for the move event + // to prevent map move events from being fired during a drag. window.document.addEventListener('mousemove', this._onMove, {capture: true}); window.document.addEventListener('mouseup', this._onUp); - /* Deactivate DragRotate when the window looses focus. Otherwise if a mouseup occurs when the window isn't in focus, DragRotate will still be active even though the mouse is no longer pressed. */ + + // Deactivate when the window loses focus. Otherwise if a mouseup occurs when the window + // isn't in focus, dragging will continue even though the mouse is no longer pressed. window.addEventListener('blur', this._onUp); this._active = false;