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
+7 -7
View File
@@ -81,15 +81,15 @@ class DragPan extends PointerInteraction {
this.kinetic_.update(centroid[0], centroid[1]);
}
if (this.lastCentroid) {
const deltaX = this.lastCentroid[0] - centroid[0];
const deltaY = centroid[1] - this.lastCentroid[1];
const delta = [
this.lastCentroid[0] - centroid[0],
centroid[1] - this.lastCentroid[1]
];
const map = mapBrowserEvent.map;
const view = map.getView();
let center = [deltaX, deltaY];
scaleCoordinate(center, view.getResolution());
rotateCoordinate(center, view.getRotation());
addCoordinate(center, view.getCenter());
view.setCenter(center);
scaleCoordinate(delta, view.getResolution());
rotateCoordinate(delta, view.getRotation());
view.adjustCenter(delta);
}
} else if (this.kinetic_) {
// reset so we don't overestimate the kinetic energy after