1
|
/*
|
2
|
Author: Steven Ottens AT geodan.nl
|
3
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
4
|
$Id$
|
5
|
*/
|
6
|
|
7
|
// Ensure this object's dependancies are loaded.
|
8
|
mapbuilder.loadScript(baseDir+"/tool/ToolBase.js");
|
9
|
|
10
|
|
11
|
/**
|
12
|
* A tool designed to store the history of the extent during a session
|
13
|
*
|
14
|
* @constructor
|
15
|
* @base ToolBase
|
16
|
* @param toolNode The node for this tool from the configuration document.
|
17
|
* @param model The model object that contains this tool
|
18
|
*/
|
19
|
function History(toolNode, model) {
|
20
|
ToolBase.apply(this, new Array(toolNode, model));
|
21
|
|
22
|
|
23
|
var doAdd = new Boolean();
|
24
|
|
25
|
/**
|
26
|
* Inititialising the history and setting start parameters
|
27
|
* @param objRef pointer to this object.
|
28
|
*/
|
29
|
|
30
|
this.init = function(objRef) {
|
31
|
place = -1;
|
32
|
list = new Array();
|
33
|
|
34
|
var bbox = objRef.targetModel.getBoundingBox();
|
35
|
newExtent = new Array();
|
36
|
newExtent[0] = new Array(bbox[0],bbox[3]);
|
37
|
newExtent[1] = new Array(bbox[2],bbox[1]);
|
38
|
list.push(newExtent);
|
39
|
|
40
|
place = place+1;
|
41
|
|
42
|
objRef.model.active = place;
|
43
|
objRef.model.historyList = list;
|
44
|
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* This adds the current extent to the historyList
|
49
|
* @param objRef pointer to this object.
|
50
|
*/
|
51
|
this.add = function(objRef) {
|
52
|
if (objRef.model.active!=null) {
|
53
|
var place = objRef.model.active;
|
54
|
var list = objRef.model.historyList;
|
55
|
newExtent = new Array();
|
56
|
newExtent[0] = objRef.model.extent.ul;
|
57
|
newExtent[1] = objRef.model.extent.lr;
|
58
|
|
59
|
if( place==(list.length-1)) { //If we are already at the end of the list add a new item
|
60
|
list.push(newExtent);
|
61
|
place = place+1;
|
62
|
}
|
63
|
else { //If we are somewhere in the middle of the list clear the rest of the list and add a new item
|
64
|
place = place+1;
|
65
|
list = list.slice(0,place);
|
66
|
list.push(newExtent);
|
67
|
}
|
68
|
objRef.model.active = place;
|
69
|
objRef.model.historyList = list;
|
70
|
}
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* This returns the previous extent in the list
|
75
|
* @param objRef pointer to this object.
|
76
|
*/
|
77
|
|
78
|
this.back = function(objRef){
|
79
|
place = objRef.model.active;
|
80
|
if(place<1) {
|
81
|
objRef.model.previousExtent = null;
|
82
|
alert("You can't go further back");
|
83
|
}
|
84
|
else {
|
85
|
place = place -1;
|
86
|
objRef.model.active = place;
|
87
|
objRef.model.previousExtent = objRef.model.historyList[place];
|
88
|
}
|
89
|
|
90
|
}
|
91
|
/**
|
92
|
* This returns the next extent in the list
|
93
|
* @param objRef pointer to this object.
|
94
|
*/
|
95
|
this.forward = function(objRef) {
|
96
|
place = objRef.model.active;
|
97
|
if(place<(objRef.model.historyList.length-1)) {
|
98
|
place = place +1;
|
99
|
objRef.model.active = place;
|
100
|
objRef.model.nextExtent = objRef.model.historyList[place];
|
101
|
}
|
102
|
else {
|
103
|
objRef.model.nextExtent = null;
|
104
|
alert("You can't go further forward");
|
105
|
}
|
106
|
}
|
107
|
|
108
|
/**
|
109
|
* This stops the listener, to prevent the undo/redo steps to appear in the list
|
110
|
* @param objRef pointer to this object.
|
111
|
*/
|
112
|
this.stop = function(objRef) {
|
113
|
objRef.model.removeListener("bbox",objRef.add, objRef);
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* This restarts the listener after undo/redo is done.
|
118
|
* @param objRef pointer to this object.
|
119
|
*/
|
120
|
this.start = function(objRef) {
|
121
|
objRef.model.addListener("bbox",objRef.add, objRef);
|
122
|
}
|
123
|
/**
|
124
|
* Set the loadModel listener in response to the init event
|
125
|
* @param objRef pointer to this object.
|
126
|
*/
|
127
|
this.initReset = function(objRef) {
|
128
|
objRef.targetModel.addListener("bbox", objRef.add, objRef);
|
129
|
objRef.targetModel.addListener("loadModel", objRef.init, objRef);
|
130
|
}
|
131
|
|
132
|
this.model.addListener("historyBack", this.back, this);
|
133
|
this.model.addListener("historyForward", this.forward, this);
|
134
|
this.model.addListener("historyStart", this.start, this);
|
135
|
this.model.addListener("historyStop", this.stop, this);
|
136
|
this.model.addListener("init", this.initReset, this);
|
137
|
}
|
138
|
|
139
|
|
140
|
|