diff --git a/examples/side-by-side.js b/examples/side-by-side.js index 1c32f475e5..411c0d0df3 100644 --- a/examples/side-by-side.js +++ b/examples/side-by-side.js @@ -113,7 +113,8 @@ keyboardInteraction.addCallback('j', function() { canvasMap.addPreRenderFunction(bounce); }); keyboardInteraction.addCallback('l', function() { - var panFrom = ol.animation.createPanFrom(view.getCenter()); + var panFrom = ol.animation.createPanFrom( + view.getCenter(), undefined, undefined, ol.easing.elastic); domMap.addPreRenderFunction(panFrom); webglMap.addPreRenderFunction(panFrom); canvasMap.addPreRenderFunction(panFrom); @@ -133,7 +134,8 @@ keyboardInteraction.addCallback('L', function() { view.setCenter(LONDON); }); keyboardInteraction.addCallback('m', function() { - var panFrom = ol.animation.createPanFrom(view.getCenter(), 1000); + var panFrom = ol.animation.createPanFrom( + view.getCenter(), 1000, undefined, ol.easing.bounce); domMap.addPreRenderFunction(panFrom); webglMap.addPreRenderFunction(panFrom); canvasMap.addPreRenderFunction(panFrom); diff --git a/src/ol/easing.js b/src/ol/easing.js index 7700c7fee6..944279cfcc 100644 --- a/src/ol/easing.js +++ b/src/ol/easing.js @@ -21,3 +21,40 @@ ol.easing.upAndDown = function(t) { return 1 - goog.fx.easing.inAndOut(2 * (t - 0.5)); } }; + + +/** + * from https://raw.github.com/DmitryBaranovskiy/raphael/master/raphael.js + * @param {number} t Input between 0 and 1. + * @return {number} Output between 0 and 1. + */ +ol.easing.elastic = function(t) { + return Math.pow(2, -10 * t) * Math.sin((t - 0.075) * (2 * Math.PI) / 0.3) + 1; +}; + + +/** + * from https://raw.github.com/DmitryBaranovskiy/raphael/master/raphael.js + * @param {number} t Input between 0 and 1. + * @return {number} Output between 0 and 1. + */ +ol.easing.bounce = function(t) { + var s = 7.5625, p = 2.75, l; + if (t < (1 / p)) { + l = s * t * t; + } else { + if (t < (2 / p)) { + t -= (1.5 / p); + l = s * t * t + 0.75; + } else { + if (t < (2.5 / p)) { + t -= (2.25 / p); + l = s * t * t + 0.9375; + } else { + t -= (2.625 / p); + l = s * t * t + 0.984375; + } + } + } + return l; +};