View / implement a smooth rebound effect when a max extent is given

This is done by applying the center constraint differently when we're in the
middle of an interaction/animation or not.

When the view is moving, the center constraint will restrain the given value
in an "elastic" way, using a logarithmic function.

This can be disabled using the `smoothCenterConstrain` view parameter.
This commit is contained in:
jahow
2019-01-14 22:30:35 +01:00
committed by Olivier Guyot
parent cd186ada7f
commit 48ad1ffcbf
4 changed files with 69 additions and 16 deletions

View File

@@ -42,7 +42,7 @@ describe('ol.View', function() {
});
});
describe('with extent option', function() {
describe('with extent option and center only', function() {
it('gives a correct center constraint function', function() {
const options = {
extent: [0, 0, 1, 1],
@@ -55,6 +55,26 @@ describe('ol.View', function() {
});
});
describe('with extent option', function() {
it('gives a correct center constraint function', function() {
const options = {
extent: [0, 0, 1, 1]
};
const fn = createCenterConstraint(options);
const res = 1;
const size = [0.15, 0.1];
expect(fn([0, 0], res, size)).to.eql([0.075, 0.05]);
expect(fn([0.5, 0.5], res, size)).to.eql([0.5, 0.5]);
expect(fn([10, 10], res, size)).to.eql([0.925, 0.95]);
const overshootCenter = fn([10, 10], res, size, true);
expect(overshootCenter[0] > 0.925).to.eql(true);
expect(overshootCenter[1] > 0.95).to.eql(true);
expect(overshootCenter[0] < 9).to.eql(true);
expect(overshootCenter[1] < 9).to.eql(true);
});
});
});
describe('create resolution constraint', function() {