Revision 4307
Added by ben leinfelder over 15 years ago
MovieLoop.js | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html |
3 | 3 |
Dependancies: Context |
4 |
$Id$ |
|
4 |
$Id: MovieLoop.js 3881 2008-02-27 15:41:07Z gjvoosten $
|
|
5 | 5 |
*/ |
6 | 6 |
|
7 | 7 |
// Ensure this object's dependancies are loaded. |
... | ... | |
24 | 24 |
this.model.setParam("firstFrame", 0); |
25 | 25 |
this.timestampIndex = 0; |
26 | 26 |
window.movieLoop = this; |
27 |
this.isRunning = false; |
|
28 |
this.frameIsLoading = false; |
|
27 | 29 |
|
28 |
// |
|
29 |
var framesPerSecond = toolNode.selectSingleNode("mb:framesPerSecond"); |
|
30 |
if (framesPerSecond) { |
|
31 |
this.delay = 1000/framesPerSecond.firstChild.nodeValue; |
|
32 |
} else { |
|
33 |
this.delay = 1000/10; //milliseconds |
|
34 |
} |
|
30 |
//delay in milliseconds |
|
31 |
this.delay = 1000/this.getProperty("mb:framesPerSecond", 10); |
|
35 | 32 |
|
36 |
//set a limit to the munber of frames to be loaded |
|
37 |
this.maxFrames = 30; |
|
38 |
var maxFrames = toolNode.selectSingleNode("mb:maxFrames"); |
|
39 |
if (maxFrames) this.maxFrames = maxFrames.firstChild.nodeValue; |
|
33 |
//set a limit to the number of frames to be loaded |
|
34 |
this.maxFrames = this.getProperty("mb:maxFrames", 30); |
|
40 | 35 |
|
41 | 36 |
/** |
42 | 37 |
* Sets the frame to the specified index in the frame array |
... | ... | |
44 | 39 |
*/ |
45 | 40 |
this.setFrame = function(index) { |
46 | 41 |
var timestampList = this.model.timestampList; |
42 |
var ts; |
|
47 | 43 |
if (this.timestampIndex!=null) { |
48 |
var timestamp = timestampList.childNodes[this.timestampIndex]; |
|
49 |
timestamp.setAttribute("current", "0"); |
|
50 |
this.model.setParam("timestamp", this.timestampIndex); |
|
44 |
var ts = timestampList.childNodes[this.timestampIndex]; |
|
45 |
if (ts) { |
|
46 |
ts.setAttribute("current", "0"); |
|
47 |
this.model.setParam("timestamp", this.timestampIndex); |
|
48 |
} |
|
51 | 49 |
} |
52 | 50 |
var firstFrame = this.model.getParam("firstFrame"); |
53 | 51 |
var lastFrame = this.model.getParam("lastFrame"); |
54 | 52 |
if (index > lastFrame) index = firstFrame; |
55 | 53 |
if (index < firstFrame) index = lastFrame; |
56 | 54 |
this.timestampIndex = index; |
57 |
timestamp = timestampList.childNodes[this.timestampIndex];
|
|
58 |
timestamp.setAttribute("current", "1");
|
|
55 |
ts = timestampList.childNodes[this.timestampIndex];
|
|
56 |
ts.setAttribute("current", "1");
|
|
59 | 57 |
this.model.setParam("timestamp", this.timestampIndex); |
60 | 58 |
} |
61 | 59 |
|
62 | 60 |
/** |
63 |
* Advances the frame array by the frame increment |
|
61 |
* Advances the frame array by the frame increment. |
|
62 |
* |
|
64 | 63 |
* @param step optional parameter to override default frame increment |
65 | 64 |
*/ |
66 | 65 |
this.nextFrame = function(step) { |
67 | 66 |
var objRef = window.movieLoop; |
68 | 67 |
var increment = objRef.frameIncrement; |
69 | 68 |
if (step) increment = step; //arg passed in overrides default |
70 |
objRef.setFrame(objRef.timestampIndex + increment); |
|
69 |
if (!this.frameIsLoading) { |
|
70 |
// play() will continue calling nextFrame, so that |
|
71 |
// nextFrame() will continually be called at a regular interval, until the current frame is loaded |
|
72 |
// The 'bug' is that if the user clicks the next button rapidly, subsequent requests will be ignored |
|
73 |
// while the initial frame is loading. This needs to be resolved. |
|
74 |
objRef.setFrame(objRef.timestampIndex + increment); |
|
75 |
} |
|
71 | 76 |
} |
72 | 77 |
|
73 | 78 |
/** |
... | ... | |
96 | 101 |
objRef.setFrame(objRef.model.getParam("firstFrame")); |
97 | 102 |
} |
98 | 103 |
this.model.addListener("loadModel",this.reset,this); |
99 |
this.model.addListener("bbox",this.reset,this); |
|
104 |
|
|
105 |
/** |
|
106 |
* initialize the movie loop. This only happens at the first bbox event, |
|
107 |
* which shows us that the map is loaded. |
|
108 |
*/ |
|
109 |
this.init = function(objRef) { |
|
110 |
//TBD: this is an ugly workaround because we do not have an event that |
|
111 |
// tells us when the OL map finished loading. |
|
112 |
if (!objRef.initialized) { |
|
113 |
objRef.initialized = true; |
|
114 |
objRef.reset(objRef); |
|
115 |
} |
|
116 |
} |
|
117 |
this.model.addListener("bbox", this.init, this); |
|
118 |
|
|
119 |
/** |
|
120 |
* set the initialized state of the movie loop to false |
|
121 |
*/ |
|
122 |
this.uninit = function(objRef) { |
|
123 |
objRef.initialized = false; |
|
124 |
} |
|
125 |
this.model.addListener("newModel", this.uninit, this); |
|
100 | 126 |
|
101 | 127 |
/** |
102 | 128 |
* Starts the movie loop playing by using a JavaScript timer. |
103 | 129 |
*/ |
104 | 130 |
this.play = function() { |
105 |
this.movieTimer = setInterval('window.movieLoop.nextFrame()',this.delay); |
|
131 |
if (!this.isRunning) { |
|
132 |
this.movieTimer = setInterval('window.movieLoop.nextFrame()',this.delay); |
|
133 |
this.isRunning = true; |
|
134 |
} |
|
106 | 135 |
} |
107 | 136 |
|
108 | 137 |
/** |
109 | 138 |
* Stops the JavaScript movie loop timer. |
110 | 139 |
*/ |
111 | 140 |
this.pause = function() { |
141 |
this.isRunning = false; |
|
112 | 142 |
clearInterval(this.movieTimer); |
113 | 143 |
} |
114 | 144 |
|
... | ... | |
116 | 146 |
* Stops the JavaScript movie loop timer and sets the index back to the first |
117 | 147 |
* frame. |
118 | 148 |
*/ |
119 |
this.stop = function() { |
|
149 |
this.stop = function() {
|
|
120 | 150 |
this.pause(); |
121 | 151 |
this.reset(this); |
122 | 152 |
} |
Also available in: Unified diff
upgrade to MapBuilder 1.5rc2 - includes support for Firefox 3 compatibility (yes, it is also EOLed)