Revision 4307
Added by ben leinfelder over 15 years ago
Mapbuilder.js | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html |
3 |
$Id$ |
|
3 |
$Id: Mapbuilder.js 3819 2008-02-01 00:31:29Z ahocevar $
|
|
4 | 4 |
*/ |
5 | 5 |
|
6 | 6 |
/** get a time stamp at start of the page load */ |
... | ... | |
9 | 9 |
/** the global config object */ |
10 | 10 |
var config; |
11 | 11 |
|
12 |
if( typeof baseDir == "undefined") { |
|
12 | 13 |
/** URL of Mapbuilder's lib/ directory. */ |
13 | 14 |
var baseDir; |
15 |
} |
|
14 | 16 |
|
15 | 17 |
/** mapbuilder environement settings, defaults to a .xml extension but is |
16 | 18 |
auto-configured by the ant build script to .jsp for tomcat environment |
... | ... | |
52 | 54 |
/** Array of objects that are loading. Don't continue initialisation until |
53 | 55 |
* all objects have loaded. */ |
54 | 56 |
this.loadingScripts=new Array(); |
57 |
|
|
58 |
/** Array of scripts that have to be loaded ordered */ |
|
59 |
this.orderedScripts = new Array(); |
|
60 |
|
|
61 |
/** Timer to load ordered scripts */ |
|
62 |
this.scriptLoader = null; |
|
55 | 63 |
|
56 | 64 |
/** Timer to periodically check if scripts have loaded. */ |
57 | 65 |
this.scriptsTimer=null; |
... | ... | |
74 | 82 |
{ |
75 | 83 |
this.loadingScripts.shift(); |
76 | 84 |
} |
77 |
if (this.loadingScripts.length==0){ |
|
85 |
if (this.loadingScripts.length==0 && this.orderedScripts.length == 0){
|
|
78 | 86 |
this.setLoadState(this.loadState+1); |
79 | 87 |
} |
80 | 88 |
} |
... | ... | |
95 | 103 |
this.loadState=newState; |
96 | 104 |
switch (newState){ |
97 | 105 |
case MB_LOAD_CORE: |
106 |
// core scripts have to be loaded in the correct order (needed for IE) |
|
107 |
this.loadOrdered = true; |
|
108 |
this.loadScript(baseDir+"/util/openlayers/OpenLayers.js"); |
|
98 | 109 |
this.loadScript(baseDir+"/util/sarissa/Sarissa.js"); |
99 |
//this.loadScript(baseDir+"/util/sarissa/sarissa_dhtml.js"); |
|
110 |
this.loadScript(baseDir+"/util/sarissa/javeline_xpath.js"); |
|
111 |
this.loadScript(baseDir+"/util/sarissa/javeline_xslt.js"); |
|
112 |
this.loadScript(baseDir+"/util/sarissa/sarissa_dhtml.js"); |
|
100 | 113 |
this.loadScript(baseDir+"/util/sarissa/sarissa_ieemu_xpath.js"); |
101 | 114 |
//this.loadScript(baseDir+"/util/sarissa/sarissa_ieemu_xslt.js");//all deprecated |
115 |
this.loadScript(baseDir+"/util/proj4js/proj4js-compressed.js"); |
|
102 | 116 |
this.loadScript(baseDir+"/util/Util.js"); |
103 | 117 |
this.loadScript(baseDir+"/util/Listener.js"); |
104 | 118 |
this.loadScript(baseDir+"/model/ModelBase.js"); |
105 | 119 |
this.loadScript(baseDir+"/model/Config.js"); |
120 |
// from now on, scripts can be loaded in any order |
|
121 |
this.loadOrdered = false; |
|
106 | 122 |
break; |
107 | 123 |
case MB_LOAD_CONFIG: |
108 | 124 |
if(document.readyState){ |
... | ... | |
115 | 131 |
} |
116 | 132 |
break; |
117 | 133 |
case MB_LOADED: |
118 |
clearInterval(this.scriptsTimer); |
|
119 |
|
|
120 |
/* |
|
121 |
* Test for XSLT support |
|
122 |
* if not, redirect to an appropriate message. |
|
123 |
*/ |
|
124 |
if (typeof XSLTProcessor != "undefined") { |
|
125 |
var UA = navigator.userAgent; |
|
126 |
var AV = navigator.appVersion; |
|
127 |
|
|
128 |
// KHTML browsers should be detected by the typeof comparison |
|
129 |
//khtml = ((AV.indexOf("Konqueror") >= 0)||(AV.indexOf("Safari") >= 0)) ? true : false; |
|
130 |
|
|
131 |
// Opera slips through the cracks |
|
132 |
opera = UA.indexOf("Opera") == -1 ? false : true; |
|
133 |
|
|
134 |
if (opera) { |
|
135 |
window.location = baseDir+"/util/noxslt.html"; |
|
136 |
} |
|
137 |
} else { |
|
138 |
window.location = baseDir+"/util/noxslt.html"; |
|
139 |
} |
|
140 |
|
|
134 |
window.clearInterval(this.scriptsTimer); |
|
141 | 135 |
break; |
142 | 136 |
} |
143 | 137 |
} |
... | ... | |
145 | 139 |
/** |
146 | 140 |
* Dynamically load a script file if it has not already been loaded. |
147 | 141 |
* @param url The url of the script. |
142 |
* that loadScript was called |
|
148 | 143 |
*/ |
149 | 144 |
this.loadScript=function(url){ |
145 |
// if we are working with a compressed build, load only scripts that |
|
146 |
// are not part of the compressed build. This check is done by looking |
|
147 |
// into the global namespace for a function that has the same name as |
|
148 |
// the script file (without path and without .js). Because script files |
|
149 |
// in the util dir do not follow that pattern, exclude them from the |
|
150 |
// check separately. |
|
151 |
if(typeof MapBuilder_Release == "boolean") { |
|
152 |
if (url.indexOf(baseDir+"/util/") != -1) { |
|
153 |
return; |
|
154 |
} |
|
155 |
var urlElements = url.split("/"); |
|
156 |
var scriptClass = urlElements[urlElements.length-1].replace(/.js$/, ""); |
|
157 |
if(typeof window[scriptClass] == "function") { |
|
158 |
return; |
|
159 |
} |
|
160 |
} |
|
161 |
|
|
150 | 162 |
if(!document.getElementById(url)){ |
151 | 163 |
var script = document.createElement('script'); |
164 |
script.src = url; |
|
165 |
script.id = url; |
|
152 | 166 |
script.defer = false; //not sure of effect of this? |
153 | 167 |
script.type = "text/javascript"; |
154 |
script.src = url; |
|
155 |
script.id = url; |
|
156 |
document.getElementsByTagName('head')[0].appendChild(script); |
|
157 |
this.loadingScripts.push(script); |
|
168 |
if (document.readyState && this.loadOrdered == true) { |
|
169 |
// in IE, mark the script as ordered |
|
170 |
this.orderedScripts.push(script); |
|
171 |
if (!this.scriptLoader) { |
|
172 |
this.scriptLoader = window.setInterval('mapbuilder.loadNextScript()', 50); |
|
173 |
} |
|
174 |
} else { |
|
175 |
// add to dom tree, except if we are using IE and want to load ordered |
|
176 |
document.getElementsByTagName('head')[0].appendChild(script); |
|
177 |
} |
|
178 |
if (document.readyState) { |
|
179 |
// this is only needed for IE |
|
180 |
this.loadingScripts.push(script); |
|
181 |
} |
|
158 | 182 |
} |
159 | 183 |
} |
184 |
|
|
185 |
/** |
|
186 |
* loads one script after another - only for IE. This function is run in a |
|
187 |
* 50ms interval and clears its interval if there are no more scripts to |
|
188 |
* load. It actually loads the first script from the orderedScripts array. |
|
189 |
*/ |
|
190 |
this.loadNextScript = function() { |
|
191 |
if (this.orderedScripts.length == 0) { |
|
192 |
window.clearInterval(this.scriptLoader); |
|
193 |
this.scriptLoader = null; |
|
194 |
} else { |
|
195 |
var script = this.orderedScripts[0]; |
|
196 |
if (!script.loading) { |
|
197 |
script.loading = true; |
|
198 |
this.doLoadScript(script); |
|
199 |
} |
|
200 |
} |
|
201 |
} |
|
202 |
|
|
203 |
/** |
|
204 |
* starts script loading by adding the script node to the dom tree - IE only. |
|
205 |
* This function adds a readyState handler to the script node. |
|
206 |
*/ |
|
207 |
this.doLoadScript = function(script) { |
|
208 |
var objRef = this; |
|
209 |
script.onreadystatechange = function(){objRef.checkScriptState(this)}; |
|
210 |
document.getElementsByTagName('head')[0].appendChild(script); |
|
211 |
} |
|
212 |
|
|
213 |
/** |
|
214 |
* readyState handler for scripts - IE only. This will remove the script from |
|
215 |
* the array of scripts that have still to be loaded. |
|
216 |
*/ |
|
217 |
this.checkScriptState = function(script) { |
|
218 |
if (script.readyState == "loaded" || script.readyState == "complete") { |
|
219 |
for (var i=0; i<this.orderedScripts.length; i++) { |
|
220 |
if (script == this.orderedScripts[i]) { |
|
221 |
this.orderedScripts.splice(i, 1); |
|
222 |
break; |
|
223 |
} |
|
224 |
} |
|
225 |
} |
|
226 |
} |
|
160 | 227 |
|
161 | 228 |
/** |
162 | 229 |
* Internal function to load scripts for components that don't have <scriptfile> |
... | ... | |
175 | 242 |
} |
176 | 243 |
|
177 | 244 |
//derive the baseDir value by looking for the script tag that loaded this file |
178 |
var head = document.getElementsByTagName('head')[0]; |
|
179 |
var nodes = head.childNodes; |
|
180 |
for (var i=0; i<nodes.length; ++i ){ |
|
181 |
var src = nodes.item(i).src; |
|
182 |
if (src) { |
|
183 |
var index = src.indexOf("/Mapbuilder.js"); |
|
184 |
if (index>=0) { |
|
185 |
baseDir = src.substring(0, index); |
|
245 |
if (!baseDir) { |
|
246 |
var head = document.getElementsByTagName('head')[0]; |
|
247 |
var nodes = head.childNodes; |
|
248 |
for (var i=0; i<nodes.length; ++i ){ |
|
249 |
var src = nodes.item(i).src; |
|
250 |
if (src) { |
|
251 |
//var index = src.indexOf("/Mapbuilder.js"); |
|
252 |
// Modified so it will work with original or compressed file |
|
253 |
var index = src.indexOf("/Mapbuilder.js"); |
|
254 |
if (index>=0) { |
|
255 |
baseDir = src.substring(0, index); |
|
256 |
} else { |
|
257 |
index = src.indexOf("/MapbuilderCompressed.js"); |
|
258 |
if (index>=0) { |
|
259 |
baseDir = src.substring(0, index); |
|
260 |
} |
|
261 |
} |
|
186 | 262 |
} |
187 | 263 |
} |
188 | 264 |
} |
... | ... | |
191 | 267 |
this.setLoadState(MB_LOAD_CORE); |
192 | 268 |
|
193 | 269 |
// Start a timer which periodically calls checkScriptsLoaded(). |
194 |
this.scriptsTimer=setInterval('mapbuilder.checkScriptsLoaded()',100); |
|
270 |
this.scriptsTimer=window.setInterval('mapbuilder.checkScriptsLoaded()',100);
|
|
195 | 271 |
} |
196 | 272 |
|
197 | 273 |
/** |
... | ... | |
224 | 300 |
*/ |
225 | 301 |
function mapbuilderInit(){ |
226 | 302 |
if(mapbuilder && mapbuilder.loadState==MB_LOADED){ |
227 |
clearInterval(mbTimerId); |
|
303 |
window.clearInterval(mbTimerId);
|
|
228 | 304 |
config.parseConfig(config); |
305 |
if (Proj4js) { |
|
306 |
Proj4js.libPath = baseDir+"/util/proj4js/"; |
|
307 |
Proj4js.proxyScript = config.proxyUrl+'?url='; |
|
308 |
} |
|
229 | 309 |
config.callListeners("init"); |
230 | 310 |
var mbTimerStop = new Date(); |
231 | 311 |
//alert("load time:"+(mbTimerStop.getTime()-mbTimerStart.getTime()) ); |
... | ... | |
247 | 327 |
*/ |
248 | 328 |
function mbDoLoad(initFunction) { |
249 | 329 |
// See if scripts have been loaded every 100msecs, then call config.init(). |
250 |
mbTimerId=setInterval('mapbuilderInit()',100); |
|
330 |
mbTimerId=window.setInterval('mapbuilderInit()',100);
|
|
251 | 331 |
if (initFunction) window.mbInit = initFunction; |
252 | 332 |
} |
Also available in: Unified diff
upgrade to MapBuilder 1.5rc2 - includes support for Firefox 3 compatibility (yes, it is also EOLed)