From e12458b32e8df7e9c4af603d7a56632ab7e9817b Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sat, 9 Mar 2013 02:02:19 +0100 Subject: [PATCH 1/5] Expose all goog.fx.easing functions in the ol.easing namespace --- src/ol/easing.exports | 3 +++ src/ol/easing.js | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/ol/easing.exports b/src/ol/easing.exports index 62418771ad..3b201be1ed 100644 --- a/src/ol/easing.exports +++ b/src/ol/easing.exports @@ -3,3 +3,6 @@ @exportProperty ol.easing.upAndDown @exportProperty ol.easing.elastic @exportProperty ol.easing.bounce +@exportProperty ol.easing.easeIn +@exportProperty ol.easing.easeOut +@exportProperty ol.easing.inAndOut diff --git a/src/ol/easing.js b/src/ol/easing.js index 944279cfcc..8ae909a86f 100644 --- a/src/ol/easing.js +++ b/src/ol/easing.js @@ -1,5 +1,28 @@ goog.provide('ol.easing'); +goog.require('goog.fx.easing'); + + +/** + * @param {number} t Input between 0 and 1. + * @return {number} Output between 0 and 1. + */ +ol.easing.easeIn = goog.fx.easing.easeIn; + + +/** + * @param {number} t Input between 0 and 1. + * @return {number} Output between 0 and 1. + */ +ol.easing.easeOut = goog.fx.easing.easeOut; + + +/** + * @param {number} t Input between 0 and 1. + * @return {number} Output between 0 and 1. + */ +ol.easing.inAndOut = goog.fx.easing.inAndOut; + /** * @param {number} t Input between 0 and 1. From 77bd27916087b9cf724de562d3e89d12a1297d2f Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sat, 9 Mar 2013 02:03:59 +0100 Subject: [PATCH 2/5] Use ol.easing instead of goog.fx.easing --- src/ol/animation.js | 5 ++--- src/ol/easing.js | 4 ++-- src/ol/view2d.js | 9 ++++----- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/ol/animation.js b/src/ol/animation.js index 74a7120de2..e15d3bffab 100644 --- a/src/ol/animation.js +++ b/src/ol/animation.js @@ -2,7 +2,6 @@ goog.provide('ol.animation'); -goog.require('goog.fx.easing'); goog.require('ol.PreRenderFunction'); goog.require('ol.ViewHint'); goog.require('ol.easing'); @@ -48,7 +47,7 @@ ol.animation.pan = function(options) { var sourceY = source.y; var duration = goog.isDef(options.duration) ? options.duration : 1000; var easing = goog.isDef(options.easing) ? - options.easing : goog.fx.easing.inAndOut; + options.easing : ol.easing.inAndOut; return function(map, frameState) { if (frameState.time < start) { frameState.animate = true; @@ -79,7 +78,7 @@ ol.animation.rotate = function(options) { var start = goog.isDef(options.start) ? options.start : goog.now(); var duration = goog.isDef(options.duration) ? options.duration : 1000; var easing = goog.isDef(options.easing) ? - options.easing : goog.fx.easing.inAndOut; + options.easing : ol.easing.inAndOut; return function(map, frameState) { if (frameState.time < start) { diff --git a/src/ol/easing.js b/src/ol/easing.js index 8ae909a86f..51a03a0ba3 100644 --- a/src/ol/easing.js +++ b/src/ol/easing.js @@ -39,9 +39,9 @@ ol.easing.linear = function(t) { */ ol.easing.upAndDown = function(t) { if (t < 0.5) { - return goog.fx.easing.inAndOut(2 * t); + return ol.easing.inAndOut(2 * t); } else { - return 1 - goog.fx.easing.inAndOut(2 * (t - 0.5)); + return 1 - ol.easing.inAndOut(2 * (t - 0.5)); } }; diff --git a/src/ol/view2d.js b/src/ol/view2d.js index 0f8bd61df6..d33ac86875 100644 --- a/src/ol/view2d.js +++ b/src/ol/view2d.js @@ -4,7 +4,6 @@ goog.provide('ol.View2D'); goog.provide('ol.View2DProperty'); -goog.require('goog.fx.easing'); goog.require('ol.Constraints'); goog.require('ol.Coordinate'); goog.require('ol.Extent'); @@ -308,13 +307,13 @@ ol.View2D.prototype.rotateWithoutConstraints = map.addPreRenderFunction(ol.animation.rotate({ rotation: currentRotation, duration: opt_duration, - easing: goog.fx.easing.easeOut + easing: ol.easing.easeOut })); if (goog.isDef(opt_anchor)) { map.addPreRenderFunction(ol.animation.pan({ source: currentCenter, duration: opt_duration, - easing: goog.fx.easing.easeOut + easing: ol.easing.easeOut })); } } @@ -382,13 +381,13 @@ ol.View2D.prototype.zoomWithoutConstraints = map.addPreRenderFunction(ol.animation.zoom({ resolution: currentResolution, duration: opt_duration, - easing: goog.fx.easing.easeOut + easing: ol.easing.easeOut })); if (goog.isDef(opt_anchor)) { map.addPreRenderFunction(ol.animation.pan({ source: currentCenter, duration: opt_duration, - easing: goog.fx.easing.easeOut + easing: ol.easing.easeOut })); } } From 9d950525bbf775e30df5fda026a6b2bf3a88e0b5 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sat, 9 Mar 2013 02:15:32 +0100 Subject: [PATCH 3/5] Default to easing inAndOut for all animations --- src/ol/animation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ol/animation.js b/src/ol/animation.js index e15d3bffab..7c0b4dffdf 100644 --- a/src/ol/animation.js +++ b/src/ol/animation.js @@ -109,7 +109,7 @@ ol.animation.zoom = function(options) { var start = goog.isDef(options.start) ? options.start : goog.now(); var duration = goog.isDef(options.duration) ? options.duration : 1000; var easing = goog.isDef(options.easing) ? - options.easing : ol.easing.linear; + options.easing : ol.easing.inAndOut; return function(map, frameState) { if (frameState.time < start) { frameState.animate = true; From 194edc7f26dae4b3998c64b360e1643093fb9e01 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sat, 9 Mar 2013 02:19:35 +0100 Subject: [PATCH 4/5] Sort functions alphabetically --- src/ol/easing.js | 74 ++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/ol/easing.js b/src/ol/easing.js index 51a03a0ba3..9e829f3a93 100644 --- a/src/ol/easing.js +++ b/src/ol/easing.js @@ -3,6 +3,33 @@ goog.provide('ol.easing'); goog.require('goog.fx.easing'); +/** + * 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; +}; + + /** * @param {number} t Input between 0 and 1. * @return {number} Output between 0 and 1. @@ -17,6 +44,16 @@ ol.easing.easeIn = goog.fx.easing.easeIn; ol.easing.easeOut = goog.fx.easing.easeOut; +/** + * 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; +}; + + /** * @param {number} t Input between 0 and 1. * @return {number} Output between 0 and 1. @@ -44,40 +81,3 @@ ol.easing.upAndDown = function(t) { return 1 - ol.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; -}; From 4a7a5fe22064b101445a1ad1c0aabd97e37265d4 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sat, 9 Mar 2013 02:22:16 +0100 Subject: [PATCH 5/5] Sort properties alphabetically --- examples/animation.js | 12 ++++++------ src/ol/easing.exports | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/animation.js b/examples/animation.js index 3257139fe0..f287201039 100644 --- a/examples/animation.js +++ b/examples/animation.js @@ -56,8 +56,8 @@ rotateRight.addEventListener('click', function() { var panToLondon = document.getElementById('pan-to-london'); panToLondon.addEventListener('click', function() { var pan = ol.animation.pan({ - source: map.getView().getView2D().getCenter(), - duration: 2000 + duration: 2000, + source: map.getView().getView2D().getCenter() }); map.addPreRenderFunction(pan); map.getView().getView2D().setCenter(london); @@ -66,9 +66,9 @@ panToLondon.addEventListener('click', function() { var elasticToMoscow = document.getElementById('elastic-to-moscow'); elasticToMoscow.addEventListener('click', function() { var pan = ol.animation.pan({ - source: map.getView().getView2D().getCenter(), duration: 2000, - easing: ol.easing.elastic + easing: ol.easing.elastic, + source: map.getView().getView2D().getCenter() }); map.addPreRenderFunction(pan); map.getView().getView2D().setCenter(moscow); @@ -77,9 +77,9 @@ elasticToMoscow.addEventListener('click', function() { var bounceToInstanbul = document.getElementById('bounce-to-instanbul'); bounceToInstanbul.addEventListener('click', function() { var pan = ol.animation.pan({ - source: map.getView().getView2D().getCenter(), duration: 2000, - easing: ol.easing.bounce + easing: ol.easing.bounce, + source: map.getView().getView2D().getCenter() }); map.addPreRenderFunction(pan); map.getView().getView2D().setCenter(instanbul); diff --git a/src/ol/easing.exports b/src/ol/easing.exports index 3b201be1ed..9ea3bdc094 100644 --- a/src/ol/easing.exports +++ b/src/ol/easing.exports @@ -1,8 +1,8 @@ @exportSymbol ol.easing -@exportProperty ol.easing.linear -@exportProperty ol.easing.upAndDown -@exportProperty ol.easing.elastic @exportProperty ol.easing.bounce @exportProperty ol.easing.easeIn @exportProperty ol.easing.easeOut +@exportProperty ol.easing.elastic @exportProperty ol.easing.inAndOut +@exportProperty ol.easing.linear +@exportProperty ol.easing.upAndDown