1
|
/*
|
2
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
3
|
Dependancies: Context
|
4
|
$Id: Timer.js 3881 2008-02-27 15:41:07Z gjvoosten $
|
5
|
*/
|
6
|
|
7
|
// Ensure this object's dependancies are loaded.
|
8
|
mapbuilder.loadScript(baseDir+"/tool/ToolBase.js");
|
9
|
|
10
|
/**
|
11
|
* Timer to fire an event at the specified interval. Any MapBuilder event name may be used,
|
12
|
* and the eventValue may be a funtion call which returns the expected value for setParam().
|
13
|
* @constructor
|
14
|
* @base ToolBase
|
15
|
* @author Adair
|
16
|
* @author Ian Turton
|
17
|
* @param toolNode The tool node from the config document for this tool
|
18
|
* @param model the model object that contains this tool
|
19
|
*/
|
20
|
function Timer(toolNode, model) {
|
21
|
ToolBase.apply(this, new Array(toolNode, model));
|
22
|
|
23
|
//delay in milliseconds - defaults to every half hour
|
24
|
this.delay = 1000*this.getProperty("mb:every", 30);
|
25
|
|
26
|
//set the event to be fired, default event is to reload the model
|
27
|
this.eventName = this.getProperty("mb:eventName", "reloadModel");
|
28
|
|
29
|
//set the value to be passed with the event, default eventValue is null
|
30
|
this.eventValue = this.getProperty("mb:eventValue");
|
31
|
|
32
|
/**
|
33
|
* Starts the timer playing by using a JavaScript timer.
|
34
|
*/
|
35
|
this.play = function() {
|
36
|
clearInterval(this.interval);
|
37
|
var workString = "config.objects."+this.targetModel.id+".setParam('"+this.eventName+"'";
|
38
|
if (this.eventValue) workString += ","+this.eventValue;
|
39
|
workString += ")";
|
40
|
//alert("about to set timer for "+this.delay+" millisecs: "+workString);
|
41
|
this.interval = setInterval(workString,this.delay);
|
42
|
}
|
43
|
|
44
|
/**
|
45
|
* Stops the JavaScript timer.
|
46
|
*/
|
47
|
this.stop = function() {
|
48
|
clearInterval(this.interval);
|
49
|
}
|
50
|
|
51
|
//the timer can start automatically or not, in which case there should be a call to timer.start() somewhere
|
52
|
this.autoStart = Mapbuilder.parseBoolean(this.getProperty("mb:autoStart", true));
|
53
|
this.startOnLoad = function(objRef) {
|
54
|
if (objRef.autoStart) objRef.play();
|
55
|
}
|
56
|
this.model.addListener("init",this.startOnLoad, this);
|
57
|
|
58
|
}
|
59
|
|
60
|
|
61
|
|