From 4e1ece16edf8b7121e75d815d9e759b1e6eaee5d Mon Sep 17 00:00:00 2001 From: Olivier Guyot Date: Sun, 6 Jan 2019 10:46:52 +0100 Subject: [PATCH] View / implemented begin- and endInteraction methods --- src/ol/View.js | 16 ++++++++++++++++ src/ol/control/ZoomSlider.js | 4 ++-- src/ol/interaction/DragPan.js | 4 ++-- src/ol/interaction/DragRotate.js | 4 ++-- src/ol/interaction/DragRotateAndZoom.js | 4 ++-- src/ol/interaction/MouseWheelZoom.js | 4 ++-- src/ol/interaction/PinchRotate.js | 4 ++-- src/ol/interaction/PinchZoom.js | 4 ++-- test/spec/ol/view.test.js | 17 +++++++++++++++++ 9 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/ol/View.js b/src/ol/View.js index 96d1195371..81c5aa07e5 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -1201,6 +1201,22 @@ class View extends BaseObject { this.cancelAnimations(); } } + + /** + * Notify the View that an interaction has started. + * @api + */ + beginInteraction() { + this.setHint(ViewHint.INTERACTING, 1); + } + + /** + * Notify the View that an interaction has ended. + * @api + */ + endInteraction() { + this.setHint(ViewHint.INTERACTING, -1); + } } diff --git a/src/ol/control/ZoomSlider.js b/src/ol/control/ZoomSlider.js index fa0b3560cb..d46ae6eff9 100644 --- a/src/ol/control/ZoomSlider.js +++ b/src/ol/control/ZoomSlider.js @@ -233,7 +233,7 @@ class ZoomSlider extends Control { */ handleDraggerStart_(event) { if (!this.dragging_ && event.originalEvent.target === this.element.firstElementChild) { - this.getMap().getView().setHint(ViewHint.INTERACTING, 1); + this.getMap().getView().beginInteraction(); this.previousX_ = event.clientX; this.previousY_ = event.clientY; this.dragging_ = true; @@ -279,7 +279,7 @@ class ZoomSlider extends Control { handleDraggerEnd_(event) { if (this.dragging_) { const view = this.getMap().getView(); - view.setHint(ViewHint.INTERACTING, -1); + view.endInteraction(); view.animate({ resolution: view.constrainResolution(this.currentResolution_), diff --git a/src/ol/interaction/DragPan.js b/src/ol/interaction/DragPan.js index d889830f33..80d9905562 100644 --- a/src/ol/interaction/DragPan.js +++ b/src/ol/interaction/DragPan.js @@ -76,7 +76,7 @@ class DragPan extends PointerInteraction { handleDragEvent(mapBrowserEvent) { if (!this.panning_) { this.panning_ = true; - this.getMap().getView().setHint(ViewHint.INTERACTING, 1); + this.getMap().getView().beginInteraction(); } const targetPointers = this.targetPointers; const centroid = centroidFromPointers(targetPointers); @@ -129,7 +129,7 @@ class DragPan extends PointerInteraction { } if (this.panning_) { this.panning_ = false; - view.setHint(ViewHint.INTERACTING, -1); + view.endInteraction(); } return false; } else { diff --git a/src/ol/interaction/DragRotate.js b/src/ol/interaction/DragRotate.js index 68995ccf08..bc10813b08 100644 --- a/src/ol/interaction/DragRotate.js +++ b/src/ol/interaction/DragRotate.js @@ -97,7 +97,7 @@ class DragRotate extends PointerInteraction { const map = mapBrowserEvent.map; const view = map.getView(); - view.setHint(ViewHint.INTERACTING, -1); + view.endInteraction(); const rotation = view.getRotation(); rotate(view, rotation, undefined, this.duration_); return false; @@ -114,7 +114,7 @@ class DragRotate extends PointerInteraction { if (mouseActionButton(mapBrowserEvent) && this.condition_(mapBrowserEvent)) { const map = mapBrowserEvent.map; - map.getView().setHint(ViewHint.INTERACTING, 1); + map.getView().beginInteraction(); this.lastAngle_ = undefined; return true; } else { diff --git a/src/ol/interaction/DragRotateAndZoom.js b/src/ol/interaction/DragRotateAndZoom.js index cf04606327..328e135d4b 100644 --- a/src/ol/interaction/DragRotateAndZoom.js +++ b/src/ol/interaction/DragRotateAndZoom.js @@ -113,7 +113,7 @@ class DragRotateAndZoom extends PointerInteraction { const map = mapBrowserEvent.map; const view = map.getView(); - view.setHint(ViewHint.INTERACTING, -1); + view.endInteraction(); const direction = this.lastScaleDelta_ - 1; rotate(view, view.getRotation()); zoom(view, view.getResolution(), undefined, this.duration_, direction); @@ -130,7 +130,7 @@ class DragRotateAndZoom extends PointerInteraction { } if (this.condition_(mapBrowserEvent)) { - mapBrowserEvent.map.getView().setHint(ViewHint.INTERACTING, 1); + mapBrowserEvent.map.getView().beginInteraction(); this.lastAngle_ = undefined; this.lastMagnitude_ = undefined; return true; diff --git a/src/ol/interaction/MouseWheelZoom.js b/src/ol/interaction/MouseWheelZoom.js index 726ee1ba62..e9fb98c8af 100644 --- a/src/ol/interaction/MouseWheelZoom.js +++ b/src/ol/interaction/MouseWheelZoom.js @@ -152,7 +152,7 @@ class MouseWheelZoom extends Interaction { decrementInteractingHint_() { this.trackpadTimeoutId_ = undefined; const view = this.getMap().getView(); - view.setHint(ViewHint.INTERACTING, -1); + view.endInteraction(); } /** @@ -218,7 +218,7 @@ class MouseWheelZoom extends Interaction { if (this.trackpadTimeoutId_) { clearTimeout(this.trackpadTimeoutId_); } else { - view.setHint(ViewHint.INTERACTING, 1); + view.beginInteraction(); } this.trackpadTimeoutId_ = setTimeout(this.decrementInteractingHint_.bind(this), this.trackpadEventGap_); let resolution = view.getResolution() * Math.pow(2, delta / this.trackpadDeltaPerZoom_); diff --git a/src/ol/interaction/PinchRotate.js b/src/ol/interaction/PinchRotate.js index 82f8c254e5..6ea8de2ebe 100644 --- a/src/ol/interaction/PinchRotate.js +++ b/src/ol/interaction/PinchRotate.js @@ -131,7 +131,7 @@ class PinchRotate extends PointerInteraction { if (this.targetPointers.length < 2) { const map = mapBrowserEvent.map; const view = map.getView(); - view.setHint(ViewHint.INTERACTING, -1); + view.endInteraction(); if (this.rotating_) { const rotation = view.getRotation(); rotate(view, rotation, this.anchor_, this.duration_); @@ -153,7 +153,7 @@ class PinchRotate extends PointerInteraction { this.rotating_ = false; this.rotationDelta_ = 0.0; if (!this.handlingDownUpSequence) { - map.getView().setHint(ViewHint.INTERACTING, 1); + map.getView().beginInteraction(); } return true; } else { diff --git a/src/ol/interaction/PinchZoom.js b/src/ol/interaction/PinchZoom.js index ed9446e318..b6ced12d60 100644 --- a/src/ol/interaction/PinchZoom.js +++ b/src/ol/interaction/PinchZoom.js @@ -126,7 +126,7 @@ class PinchZoom extends PointerInteraction { if (this.targetPointers.length < 2) { const map = mapBrowserEvent.map; const view = map.getView(); - view.setHint(ViewHint.INTERACTING, -1); + view.endInteraction(); const resolution = view.getResolution(); if (this.constrainResolution_ || resolution < view.getMinResolution() || @@ -153,7 +153,7 @@ class PinchZoom extends PointerInteraction { this.lastDistance_ = undefined; this.lastScaleDelta_ = 1; if (!this.handlingDownUpSequence) { - map.getView().setHint(ViewHint.INTERACTING, 1); + map.getView().beginInteraction(); } return true; } else { diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js index 321c69667c..fed967810b 100644 --- a/test/spec/ol/view.test.js +++ b/test/spec/ol/view.test.js @@ -1422,6 +1422,23 @@ describe('ol.View', function() { expect(view.getCenter()[1]).to.roughlyEqual(46000, 1e-9); }); }); + + describe('#beginInteraction() and endInteraction()', function() { + let view; + beforeEach(function() { + view = new View() + }); + + it('correctly changes the view hint', function() { + view.beginInteraction(); + expect(view.getHints()[1]).to.be(1); + view.beginInteraction(); + expect(view.getHints()[1]).to.be(2); + view.endInteraction(); + view.endInteraction(); + expect(view.getHints()[1]).to.be(0); + }); + }); }); describe('ol.View.isNoopAnimation()', function() {