View / implemented begin- and endInteraction methods
This commit is contained in:
@@ -1201,6 +1201,22 @@ class View extends BaseObject {
|
|||||||
this.cancelAnimations();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ class ZoomSlider extends Control {
|
|||||||
*/
|
*/
|
||||||
handleDraggerStart_(event) {
|
handleDraggerStart_(event) {
|
||||||
if (!this.dragging_ && event.originalEvent.target === this.element.firstElementChild) {
|
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.previousX_ = event.clientX;
|
||||||
this.previousY_ = event.clientY;
|
this.previousY_ = event.clientY;
|
||||||
this.dragging_ = true;
|
this.dragging_ = true;
|
||||||
@@ -279,7 +279,7 @@ class ZoomSlider extends Control {
|
|||||||
handleDraggerEnd_(event) {
|
handleDraggerEnd_(event) {
|
||||||
if (this.dragging_) {
|
if (this.dragging_) {
|
||||||
const view = this.getMap().getView();
|
const view = this.getMap().getView();
|
||||||
view.setHint(ViewHint.INTERACTING, -1);
|
view.endInteraction();
|
||||||
|
|
||||||
view.animate({
|
view.animate({
|
||||||
resolution: view.constrainResolution(this.currentResolution_),
|
resolution: view.constrainResolution(this.currentResolution_),
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class DragPan extends PointerInteraction {
|
|||||||
handleDragEvent(mapBrowserEvent) {
|
handleDragEvent(mapBrowserEvent) {
|
||||||
if (!this.panning_) {
|
if (!this.panning_) {
|
||||||
this.panning_ = true;
|
this.panning_ = true;
|
||||||
this.getMap().getView().setHint(ViewHint.INTERACTING, 1);
|
this.getMap().getView().beginInteraction();
|
||||||
}
|
}
|
||||||
const targetPointers = this.targetPointers;
|
const targetPointers = this.targetPointers;
|
||||||
const centroid = centroidFromPointers(targetPointers);
|
const centroid = centroidFromPointers(targetPointers);
|
||||||
@@ -129,7 +129,7 @@ class DragPan extends PointerInteraction {
|
|||||||
}
|
}
|
||||||
if (this.panning_) {
|
if (this.panning_) {
|
||||||
this.panning_ = false;
|
this.panning_ = false;
|
||||||
view.setHint(ViewHint.INTERACTING, -1);
|
view.endInteraction();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ class DragRotate extends PointerInteraction {
|
|||||||
|
|
||||||
const map = mapBrowserEvent.map;
|
const map = mapBrowserEvent.map;
|
||||||
const view = map.getView();
|
const view = map.getView();
|
||||||
view.setHint(ViewHint.INTERACTING, -1);
|
view.endInteraction();
|
||||||
const rotation = view.getRotation();
|
const rotation = view.getRotation();
|
||||||
rotate(view, rotation, undefined, this.duration_);
|
rotate(view, rotation, undefined, this.duration_);
|
||||||
return false;
|
return false;
|
||||||
@@ -114,7 +114,7 @@ class DragRotate extends PointerInteraction {
|
|||||||
|
|
||||||
if (mouseActionButton(mapBrowserEvent) && this.condition_(mapBrowserEvent)) {
|
if (mouseActionButton(mapBrowserEvent) && this.condition_(mapBrowserEvent)) {
|
||||||
const map = mapBrowserEvent.map;
|
const map = mapBrowserEvent.map;
|
||||||
map.getView().setHint(ViewHint.INTERACTING, 1);
|
map.getView().beginInteraction();
|
||||||
this.lastAngle_ = undefined;
|
this.lastAngle_ = undefined;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class DragRotateAndZoom extends PointerInteraction {
|
|||||||
|
|
||||||
const map = mapBrowserEvent.map;
|
const map = mapBrowserEvent.map;
|
||||||
const view = map.getView();
|
const view = map.getView();
|
||||||
view.setHint(ViewHint.INTERACTING, -1);
|
view.endInteraction();
|
||||||
const direction = this.lastScaleDelta_ - 1;
|
const direction = this.lastScaleDelta_ - 1;
|
||||||
rotate(view, view.getRotation());
|
rotate(view, view.getRotation());
|
||||||
zoom(view, view.getResolution(), undefined, this.duration_, direction);
|
zoom(view, view.getResolution(), undefined, this.duration_, direction);
|
||||||
@@ -130,7 +130,7 @@ class DragRotateAndZoom extends PointerInteraction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.condition_(mapBrowserEvent)) {
|
if (this.condition_(mapBrowserEvent)) {
|
||||||
mapBrowserEvent.map.getView().setHint(ViewHint.INTERACTING, 1);
|
mapBrowserEvent.map.getView().beginInteraction();
|
||||||
this.lastAngle_ = undefined;
|
this.lastAngle_ = undefined;
|
||||||
this.lastMagnitude_ = undefined;
|
this.lastMagnitude_ = undefined;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ class MouseWheelZoom extends Interaction {
|
|||||||
decrementInteractingHint_() {
|
decrementInteractingHint_() {
|
||||||
this.trackpadTimeoutId_ = undefined;
|
this.trackpadTimeoutId_ = undefined;
|
||||||
const view = this.getMap().getView();
|
const view = this.getMap().getView();
|
||||||
view.setHint(ViewHint.INTERACTING, -1);
|
view.endInteraction();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -218,7 +218,7 @@ class MouseWheelZoom extends Interaction {
|
|||||||
if (this.trackpadTimeoutId_) {
|
if (this.trackpadTimeoutId_) {
|
||||||
clearTimeout(this.trackpadTimeoutId_);
|
clearTimeout(this.trackpadTimeoutId_);
|
||||||
} else {
|
} else {
|
||||||
view.setHint(ViewHint.INTERACTING, 1);
|
view.beginInteraction();
|
||||||
}
|
}
|
||||||
this.trackpadTimeoutId_ = setTimeout(this.decrementInteractingHint_.bind(this), this.trackpadEventGap_);
|
this.trackpadTimeoutId_ = setTimeout(this.decrementInteractingHint_.bind(this), this.trackpadEventGap_);
|
||||||
let resolution = view.getResolution() * Math.pow(2, delta / this.trackpadDeltaPerZoom_);
|
let resolution = view.getResolution() * Math.pow(2, delta / this.trackpadDeltaPerZoom_);
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ class PinchRotate extends PointerInteraction {
|
|||||||
if (this.targetPointers.length < 2) {
|
if (this.targetPointers.length < 2) {
|
||||||
const map = mapBrowserEvent.map;
|
const map = mapBrowserEvent.map;
|
||||||
const view = map.getView();
|
const view = map.getView();
|
||||||
view.setHint(ViewHint.INTERACTING, -1);
|
view.endInteraction();
|
||||||
if (this.rotating_) {
|
if (this.rotating_) {
|
||||||
const rotation = view.getRotation();
|
const rotation = view.getRotation();
|
||||||
rotate(view, rotation, this.anchor_, this.duration_);
|
rotate(view, rotation, this.anchor_, this.duration_);
|
||||||
@@ -153,7 +153,7 @@ class PinchRotate extends PointerInteraction {
|
|||||||
this.rotating_ = false;
|
this.rotating_ = false;
|
||||||
this.rotationDelta_ = 0.0;
|
this.rotationDelta_ = 0.0;
|
||||||
if (!this.handlingDownUpSequence) {
|
if (!this.handlingDownUpSequence) {
|
||||||
map.getView().setHint(ViewHint.INTERACTING, 1);
|
map.getView().beginInteraction();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class PinchZoom extends PointerInteraction {
|
|||||||
if (this.targetPointers.length < 2) {
|
if (this.targetPointers.length < 2) {
|
||||||
const map = mapBrowserEvent.map;
|
const map = mapBrowserEvent.map;
|
||||||
const view = map.getView();
|
const view = map.getView();
|
||||||
view.setHint(ViewHint.INTERACTING, -1);
|
view.endInteraction();
|
||||||
const resolution = view.getResolution();
|
const resolution = view.getResolution();
|
||||||
if (this.constrainResolution_ ||
|
if (this.constrainResolution_ ||
|
||||||
resolution < view.getMinResolution() ||
|
resolution < view.getMinResolution() ||
|
||||||
@@ -153,7 +153,7 @@ class PinchZoom extends PointerInteraction {
|
|||||||
this.lastDistance_ = undefined;
|
this.lastDistance_ = undefined;
|
||||||
this.lastScaleDelta_ = 1;
|
this.lastScaleDelta_ = 1;
|
||||||
if (!this.handlingDownUpSequence) {
|
if (!this.handlingDownUpSequence) {
|
||||||
map.getView().setHint(ViewHint.INTERACTING, 1);
|
map.getView().beginInteraction();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1422,6 +1422,23 @@ describe('ol.View', function() {
|
|||||||
expect(view.getCenter()[1]).to.roughlyEqual(46000, 1e-9);
|
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() {
|
describe('ol.View.isNoopAnimation()', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user