Remove remaining static members from Interaction
This commit is contained in:
@@ -2,7 +2,6 @@ import Map from '../../../../src/ol/Map.js';
|
||||
import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import DragRotateAndZoom from '../../../../src/ol/interaction/DragRotateAndZoom.js';
|
||||
import Interaction from '../../../../src/ol/interaction/Interaction.js';
|
||||
import VectorLayer from '../../../../src/ol/layer/Vector.js';
|
||||
import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js';
|
||||
import VectorSource from '../../../../src/ol/source/Vector.js';
|
||||
@@ -62,22 +61,30 @@ describe('ol.interaction.DragRotateAndZoom', function() {
|
||||
new PointerEvent('pointermove', {clientX: 20, clientY: 10}, {pointerType: 'mouse'}),
|
||||
true);
|
||||
interaction.lastAngle_ = Math.PI;
|
||||
const spy = sinon.spy(Interaction, 'rotateWithoutConstraints');
|
||||
|
||||
let view = map.getView();
|
||||
let spy = sinon.spy(view, 'rotate');
|
||||
interaction.handleDragEvent_(event);
|
||||
expect(spy.callCount).to.be(1);
|
||||
expect(interaction.lastAngle_).to.be(-0.8308214428190254);
|
||||
map.setView(new View({
|
||||
view.rotate.restore();
|
||||
|
||||
view = new View({
|
||||
projection: 'EPSG:4326',
|
||||
center: [0, 0],
|
||||
resolution: 1,
|
||||
enableRotation: false
|
||||
}));
|
||||
});
|
||||
map.setView(view);
|
||||
|
||||
event = new MapBrowserPointerEvent('pointermove', map,
|
||||
new PointerEvent('pointermove', {clientX: 24, clientY: 16}, {pointerType: 'mouse'}),
|
||||
true);
|
||||
|
||||
spy = sinon.spy(view, 'rotate');
|
||||
interaction.handleDragEvent_(event);
|
||||
expect(spy.callCount).to.be(1);
|
||||
Interaction.rotateWithoutConstraints.restore();
|
||||
expect(spy.callCount).to.be(0);
|
||||
view.rotate.restore();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import EventTarget from '../../../../src/ol/events/EventTarget.js';
|
||||
import Interaction from '../../../../src/ol/interaction/Interaction.js';
|
||||
import Interaction, {zoomByDelta} from '../../../../src/ol/interaction/Interaction.js';
|
||||
|
||||
describe('ol.interaction.Interaction', function() {
|
||||
|
||||
@@ -64,16 +64,16 @@ describe('ol.interaction.Interaction', function() {
|
||||
resolutions: [4, 2, 1, 0.5, 0.25]
|
||||
});
|
||||
|
||||
Interaction.zoomByDelta(view, 1);
|
||||
zoomByDelta(view, 1);
|
||||
expect(view.getResolution()).to.be(0.5);
|
||||
|
||||
Interaction.zoomByDelta(view, -1);
|
||||
zoomByDelta(view, -1);
|
||||
expect(view.getResolution()).to.be(1);
|
||||
|
||||
Interaction.zoomByDelta(view, 2);
|
||||
zoomByDelta(view, 2);
|
||||
expect(view.getResolution()).to.be(0.25);
|
||||
|
||||
Interaction.zoomByDelta(view, -2);
|
||||
zoomByDelta(view, -2);
|
||||
expect(view.getResolution()).to.be(1);
|
||||
});
|
||||
|
||||
@@ -84,16 +84,16 @@ describe('ol.interaction.Interaction', function() {
|
||||
resolutions: [4, 2, 1, 0.5, 0.25]
|
||||
});
|
||||
|
||||
Interaction.zoomByDelta(view, 1, [10, 10]);
|
||||
zoomByDelta(view, 1, [10, 10]);
|
||||
expect(view.getCenter()).to.eql([5, 5]);
|
||||
|
||||
Interaction.zoomByDelta(view, -1, [0, 0]);
|
||||
zoomByDelta(view, -1, [0, 0]);
|
||||
expect(view.getCenter()).to.eql([10, 10]);
|
||||
|
||||
Interaction.zoomByDelta(view, 2, [0, 0]);
|
||||
zoomByDelta(view, 2, [0, 0]);
|
||||
expect(view.getCenter()).to.eql([2.5, 2.5]);
|
||||
|
||||
Interaction.zoomByDelta(view, -2, [0, 0]);
|
||||
zoomByDelta(view, -2, [0, 0]);
|
||||
expect(view.getCenter()).to.eql([10, 10]);
|
||||
});
|
||||
|
||||
@@ -105,16 +105,16 @@ describe('ol.interaction.Interaction', function() {
|
||||
resolutions: [4, 2, 1, 0.5, 0.25]
|
||||
});
|
||||
|
||||
Interaction.zoomByDelta(view, 1, [10, 10]);
|
||||
zoomByDelta(view, 1, [10, 10]);
|
||||
expect(view.getCenter()).to.eql([2.5, 2.5]);
|
||||
|
||||
Interaction.zoomByDelta(view, -1, [0, 0]);
|
||||
zoomByDelta(view, -1, [0, 0]);
|
||||
expect(view.getCenter()).to.eql([2.5, 2.5]);
|
||||
|
||||
Interaction.zoomByDelta(view, 2, [10, 10]);
|
||||
zoomByDelta(view, 2, [10, 10]);
|
||||
expect(view.getCenter()).to.eql([2.5, 2.5]);
|
||||
|
||||
Interaction.zoomByDelta(view, -2, [0, 0]);
|
||||
zoomByDelta(view, -2, [0, 0]);
|
||||
expect(view.getCenter()).to.eql([2.5, 2.5]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,6 @@ import Map from '../../../../src/ol/Map.js';
|
||||
import MapBrowserEvent from '../../../../src/ol/MapBrowserEvent.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import Event from '../../../../src/ol/events/Event.js';
|
||||
import Interaction from '../../../../src/ol/interaction/Interaction.js';
|
||||
|
||||
describe('ol.interaction.KeyboardPan', function() {
|
||||
let map;
|
||||
@@ -24,25 +23,35 @@ describe('ol.interaction.KeyboardPan', function() {
|
||||
|
||||
describe('handleEvent()', function() {
|
||||
it('pans on arrow keys', function() {
|
||||
const spy = sinon.spy(Interaction, 'pan');
|
||||
const view = map.getView();
|
||||
const spy = sinon.spy(view, 'animate');
|
||||
const event = new MapBrowserEvent('keydown', map, {
|
||||
type: 'keydown',
|
||||
target: map.getTargetElement(),
|
||||
preventDefault: Event.prototype.preventDefault
|
||||
});
|
||||
|
||||
event.originalEvent.keyCode = 40; // DOWN
|
||||
map.handleMapBrowserEvent(event);
|
||||
expect(spy.getCall(0).args[0].center).to.eql([0, -128]);
|
||||
view.setCenter([0, 0]);
|
||||
|
||||
event.originalEvent.keyCode = 38; // UP
|
||||
map.handleMapBrowserEvent(event);
|
||||
expect(spy.getCall(1).args[0].center).to.eql([0, 128]);
|
||||
view.setCenter([0, 0]);
|
||||
|
||||
event.originalEvent.keyCode = 37; // LEFT
|
||||
map.handleMapBrowserEvent(event);
|
||||
expect(spy.getCall(2).args[0].center).to.eql([-128, 0]);
|
||||
view.setCenter([0, 0]);
|
||||
|
||||
event.originalEvent.keyCode = 39; // RIGHT
|
||||
map.handleMapBrowserEvent(event);
|
||||
expect(spy.getCall(0).args[1]).to.eql([0, -128]);
|
||||
expect(spy.getCall(1).args[1]).to.eql([0, 128]);
|
||||
expect(spy.getCall(2).args[1]).to.eql([-128, 0]);
|
||||
expect(spy.getCall(3).args[1]).to.eql([128, 0]);
|
||||
Interaction.pan.restore();
|
||||
expect(spy.getCall(3).args[0].center).to.eql([128, 0]);
|
||||
view.setCenter([0, 0]);
|
||||
|
||||
view.animate.restore();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import Map from '../../../../src/ol/Map.js';
|
||||
import MapBrowserEvent from '../../../../src/ol/MapBrowserEvent.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import Event from '../../../../src/ol/events/Event.js';
|
||||
import Interaction from '../../../../src/ol/interaction/Interaction.js';
|
||||
|
||||
describe('ol.interaction.KeyboardZoom', function() {
|
||||
let map;
|
||||
@@ -12,8 +11,8 @@ describe('ol.interaction.KeyboardZoom', function() {
|
||||
target: createMapDiv(100, 100),
|
||||
view: new View({
|
||||
center: [0, 0],
|
||||
resolutions: [1],
|
||||
zoom: 0
|
||||
resolutions: [4, 2, 1],
|
||||
zoom: 1
|
||||
})
|
||||
});
|
||||
map.renderSync();
|
||||
@@ -24,19 +23,25 @@ describe('ol.interaction.KeyboardZoom', function() {
|
||||
|
||||
describe('handleEvent()', function() {
|
||||
it('zooms on + and - keys', function() {
|
||||
const spy = sinon.spy(Interaction, 'zoomByDelta');
|
||||
const view = map.getView();
|
||||
const spy = sinon.spy(view, 'animate');
|
||||
const event = new MapBrowserEvent('keydown', map, {
|
||||
type: 'keydown',
|
||||
target: map.getTargetElement(),
|
||||
preventDefault: Event.prototype.preventDefault
|
||||
});
|
||||
|
||||
event.originalEvent.charCode = '+'.charCodeAt(0);
|
||||
map.handleMapBrowserEvent(event);
|
||||
expect(spy.getCall(0).args[0].resolution).to.eql(1);
|
||||
view.setResolution(2);
|
||||
|
||||
event.originalEvent.charCode = '-'.charCodeAt(0);
|
||||
map.handleMapBrowserEvent(event);
|
||||
expect(spy.getCall(0).args[1]).to.eql(1);
|
||||
expect(spy.getCall(1).args[1]).to.eql(-1);
|
||||
Interaction.zoomByDelta.restore();
|
||||
expect(spy.getCall(1).args[0].resolution).to.eql(4);
|
||||
view.setResolution(2);
|
||||
|
||||
view.animate.restore();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ import MapBrowserEvent from '../../../../src/ol/MapBrowserEvent.js';
|
||||
import View from '../../../../src/ol/View.js';
|
||||
import Event from '../../../../src/ol/events/Event.js';
|
||||
import {DEVICE_PIXEL_RATIO, FIREFOX, SAFARI} from '../../../../src/ol/has.js';
|
||||
import Interaction from '../../../../src/ol/interaction/Interaction.js';
|
||||
import MouseWheelZoom, {Mode} from '../../../../src/ol/interaction/MouseWheelZoom.js';
|
||||
|
||||
|
||||
@@ -33,13 +32,13 @@ describe('ol.interaction.MouseWheelZoom', function() {
|
||||
describe('timeout duration', function() {
|
||||
let clock;
|
||||
beforeEach(function() {
|
||||
sinon.spy(Interaction, 'zoomByDelta');
|
||||
sinon.spy(interaction, 'handleWheelZoom_');
|
||||
clock = sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
clock.restore();
|
||||
Interaction.zoomByDelta.restore();
|
||||
interaction.handleWheelZoom_.restore();
|
||||
});
|
||||
|
||||
it('works with the defaut value', function(done) {
|
||||
@@ -48,12 +47,14 @@ describe('ol.interaction.MouseWheelZoom', function() {
|
||||
target: map.getViewport(),
|
||||
preventDefault: Event.prototype.preventDefault
|
||||
});
|
||||
|
||||
map.handleMapBrowserEvent(event);
|
||||
clock.tick(50);
|
||||
// default timeout is 80 ms, not called yet
|
||||
expect(Interaction.zoomByDelta.called).to.be(false);
|
||||
expect(interaction.handleWheelZoom_.called).to.be(false);
|
||||
|
||||
clock.tick(30);
|
||||
expect(Interaction.zoomByDelta.called).to.be(true);
|
||||
expect(interaction.handleWheelZoom_.called).to.be(true);
|
||||
|
||||
done();
|
||||
});
|
||||
@@ -98,21 +99,25 @@ describe('ol.interaction.MouseWheelZoom', function() {
|
||||
});
|
||||
}
|
||||
|
||||
describe('spying on ol.interaction.Interaction.zoomByDelta', function() {
|
||||
describe('spying on view.animate()', function() {
|
||||
let view;
|
||||
beforeEach(function() {
|
||||
sinon.spy(Interaction, 'zoomByDelta');
|
||||
view = map.getView();
|
||||
sinon.spy(view, 'animate');
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
Interaction.zoomByDelta.restore();
|
||||
view.animate.restore();
|
||||
});
|
||||
|
||||
it('works in DOM_DELTA_LINE mode (wheel)', function(done) {
|
||||
map.once('postrender', function() {
|
||||
const call = Interaction.zoomByDelta.getCall(0);
|
||||
expect(call.args[1]).to.be(-1);
|
||||
expect(call.args[2]).to.eql([0, 0]);
|
||||
const call = view.animate.getCall(0);
|
||||
expect(call.args[0].resolution).to.be(2);
|
||||
expect(call.args[0].anchor).to.eql([0, 0]);
|
||||
done();
|
||||
});
|
||||
|
||||
const event = new MapBrowserEvent('wheel', map, {
|
||||
type: 'wheel',
|
||||
deltaMode: WheelEvent.DOM_DELTA_LINE,
|
||||
@@ -121,17 +126,19 @@ describe('ol.interaction.MouseWheelZoom', function() {
|
||||
preventDefault: Event.prototype.preventDefault
|
||||
});
|
||||
event.coordinate = [0, 0];
|
||||
|
||||
map.handleMapBrowserEvent(event);
|
||||
});
|
||||
|
||||
if (SAFARI) {
|
||||
it('works on Safari (wheel)', function(done) {
|
||||
map.once('postrender', function() {
|
||||
const call = Interaction.zoomByDelta.getCall(0);
|
||||
expect(call.args[1]).to.be(-1);
|
||||
expect(call.args[2]).to.eql([0, 0]);
|
||||
const call = view.animate.getCall(0);
|
||||
expect(call.args[0].resolution).to.be(2);
|
||||
expect(call.args[0].anchor).to.eql([0, 0]);
|
||||
done();
|
||||
});
|
||||
|
||||
const event = new MapBrowserEvent('mousewheel', map, {
|
||||
type: 'mousewheel',
|
||||
wheelDeltaY: -50,
|
||||
@@ -139,6 +146,7 @@ describe('ol.interaction.MouseWheelZoom', function() {
|
||||
preventDefault: Event.prototype.preventDefault
|
||||
});
|
||||
event.coordinate = [0, 0];
|
||||
|
||||
map.handleMapBrowserEvent(event);
|
||||
});
|
||||
}
|
||||
@@ -146,11 +154,12 @@ describe('ol.interaction.MouseWheelZoom', function() {
|
||||
if (!SAFARI) {
|
||||
it('works on other browsers (wheel)', function(done) {
|
||||
map.once('postrender', function() {
|
||||
const call = Interaction.zoomByDelta.getCall(0);
|
||||
expect(call.args[1]).to.be(-1);
|
||||
expect(call.args[2]).to.eql([0, 0]);
|
||||
const call = view.animate.getCall(0);
|
||||
expect(call.args[0].resolution).to.be(2);
|
||||
expect(call.args[0].anchor).to.eql([0, 0]);
|
||||
done();
|
||||
});
|
||||
|
||||
const event = new MapBrowserEvent('mousewheel', map, {
|
||||
type: 'mousewheel',
|
||||
wheelDeltaY: -120,
|
||||
@@ -158,6 +167,7 @@ describe('ol.interaction.MouseWheelZoom', function() {
|
||||
preventDefault: Event.prototype.preventDefault
|
||||
});
|
||||
event.coordinate = [0, 0];
|
||||
|
||||
map.handleMapBrowserEvent(event);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user