1
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3
* full text of the license. */
6
* Namespace: OpenLayers.Tween
8
OpenLayers.Tween = OpenLayers.Class({
12
* {int} Interval in milliseconds between 2 steps
18
* {<OpenLayers.Easing>(Function)} Easing equation used for the animation
19
* Defaultly set to OpenLayers.Easing.Expo.easeOut
25
* {Object} Values to start the animation with
31
* {Object} Values to finish the animation with
36
* APIProperty: duration
37
* {int} duration of the tween (number of steps)
42
* APIProperty: callbacks
43
* {Object} An object with start, eachStep and done properties whose values
44
* are functions to be call during the animation. They are passed the
45
* current computed value as argument.
57
* {int} Interval id returned by window.setInterval
63
* {Boolean} Tells if the easing is currently playing
68
* Constructor: OpenLayers.Tween
72
* easing - {<OpenLayers.Easing>(Function)} easing function method to use
74
initialize: function(easing) {
75
this.easing = (easing) ? easing : OpenLayers.Easing.Expo.easeOut;
80
* Plays the Tween, and calls the callback method on each step
83
* begin - {Object} values to start the animation with
84
* finish - {Object} values to finish the animation with
85
* duration - {int} duration of the tween (number of steps)
86
* options - {Object} hash of options (for example callbacks (start, eachStep, done))
88
start: function(begin, finish, duration, options) {
92
this.duration = duration;
93
this.callbacks = options.callbacks;
96
window.clearInterval(this.interval);
99
if (this.callbacks && this.callbacks.start) {
100
this.callbacks.start.call(this, this.begin);
102
this.interval = window.setInterval(
103
OpenLayers.Function.bind(this.play, this), this.INTERVAL);
108
* Stops the Tween, and calls the done callback
109
* Doesn't do anything if animation is already finished
116
if (this.callbacks && this.callbacks.done) {
117
this.callbacks.done.call(this, this.finish);
119
window.clearInterval(this.interval);
120
this.interval = null;
121
this.playing = false;
126
* Calls the appropriate easing method
130
for (var i in this.begin) {
131
var b = this.begin[i];
132
var f = this.finish[i];
133
if (b == null || f == null || isNaN(b) || isNaN(f)) {
134
OpenLayers.Console.error('invalid value for Tween');
138
value[i] = this.easing.apply(this, [this.time, b, c, this.duration]);
142
if (this.callbacks && this.callbacks.eachStep) {
143
this.callbacks.eachStep.call(this, value);
146
if (this.time > this.duration) {
147
if (this.callbacks && this.callbacks.done) {
148
this.callbacks.done.call(this, this.finish);
149
this.playing = false;
151
window.clearInterval(this.interval);
152
this.interval = null;
157
* Create empty functions for all easing methods.
159
CLASS_NAME: "OpenLayers.Tween"
163
* Namespace: OpenLayers.Easing
166
* Easing Equations by Robert Penner, <http://www.robertpenner.com/easing/>
168
OpenLayers.Easing = {
170
* Create empty functions for all easing methods.
172
CLASS_NAME: "OpenLayers.Easing"
176
* Namespace: OpenLayers.Easing.Linear
178
OpenLayers.Easing.Linear = {
185
* b - {Float} beginning position
186
* c - {Float} total change
187
* d - {Float} duration of the transition
189
easeIn: function(t, b, c, d) {
198
* b - {Float} beginning position
199
* c - {Float} total change
200
* d - {Float} duration of the transition
202
easeOut: function(t, b, c, d) {
207
* Function: easeInOut
211
* b - {Float} beginning position
212
* c - {Float} total change
213
* d - {Float} duration of the transition
215
easeInOut: function(t, b, c, d) {
219
CLASS_NAME: "OpenLayers.Easing.Linear"
223
* Namespace: OpenLayers.Easing.Expo
225
OpenLayers.Easing.Expo = {
232
* b - {Float} beginning position
233
* c - {Float} total change
234
* d - {Float} duration of the transition
236
easeIn: function(t, b, c, d) {
237
return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
245
* b - {Float} beginning position
246
* c - {Float} total change
247
* d - {Float} duration of the transition
249
easeOut: function(t, b, c, d) {
250
return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
254
* Function: easeInOut
258
* b - {Float} beginning position
259
* c - {Float} total change
260
* d - {Float} duration of the transition
262
easeInOut: function(t, b, c, d) {
264
if (t==d) return b+c;
265
if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
266
return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
269
CLASS_NAME: "OpenLayers.Easing.Expo"
273
* Namespace: OpenLayers.Easing.Quad
275
OpenLayers.Easing.Quad = {
282
* b - {Float} beginning position
283
* c - {Float} total change
284
* d - {Float} duration of the transition
286
easeIn: function(t, b, c, d) {
287
return c*(t/=d)*t + b;
295
* b - {Float} beginning position
296
* c - {Float} total change
297
* d - {Float} duration of the transition
299
easeOut: function(t, b, c, d) {
300
return -c *(t/=d)*(t-2) + b;
304
* Function: easeInOut
308
* b - {Float} beginning position
309
* c - {Float} total change
310
* d - {Float} duration of the transition
312
easeInOut: function(t, b, c, d) {
313
if ((t/=d/2) < 1) return c/2*t*t + b;
314
return -c/2 * ((--t)*(t-2) - 1) + b;
317
CLASS_NAME: "OpenLayers.Easing.Quad"