View / add adjust* methods to manipulate the view more easily

API changes:
* (breaking) the `rotate` method is gone
* the `adjustRotation`, `adjustResolution` and `adjustZoom` methods are now
  available and allow using an anchor.

This means interactions do not have to do the anchor computation themselves
and this also fix anchor computation when constraints must be applied.
This commit is contained in:
Olivier Guyot
2019-01-29 12:13:27 +01:00
parent b5273babb5
commit e023c144bb
10 changed files with 237 additions and 284 deletions

View File

@@ -62,13 +62,18 @@ describe('ol.interaction.DragRotateAndZoom', function() {
true);
interaction.lastAngle_ = Math.PI;
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);
view.rotate.restore();
let callCount = 0;
let view = map.getView();
view.on('change:rotation', function() {
callCount++;
});
interaction.handleDragEvent(event);
expect(callCount).to.be(1);
expect(interaction.lastAngle_).to.be(-0.8308214428190254);
callCount = 0;
view = new View({
projection: 'EPSG:4326',
center: [0, 0],
@@ -76,15 +81,16 @@ describe('ol.interaction.DragRotateAndZoom', function() {
enableRotation: false
});
map.setView(view);
view.on('change:rotation', function() {
callCount++;
});
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(0);
view.rotate.restore();
expect(callCount).to.be(0);
});
});