Revision 4307
Added by ben leinfelder over 15 years ago
OwsContext.js | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html |
3 |
$Id$ |
|
3 |
$Id: OwsContext.js 3887 2008-02-27 18:18:53Z ahocevar $
|
|
4 | 4 |
*/ |
5 | 5 |
|
6 |
// Ensure this object's dependancies are loaded. |
|
7 |
mapbuilder.loadScript(baseDir+"/model/ModelBase.js"); |
|
8 |
|
|
6 | 9 |
/** |
7 | 10 |
* Stores an OWS Context document as defined by the OGC interoperability |
8 |
* experiment. This model should be eventually merged with the standard OGC
|
|
11 |
* experiment. This model should be eventually merged with the standard OGC |
|
9 | 12 |
* context doc. |
10 | 13 |
* Listeners supported by this model: |
11 | 14 |
* "refresh" called when window parameters (width/height, bbox) are changed |
... | ... | |
16 | 19 |
* @base ModelBase |
17 | 20 |
* @author Mike Adair |
18 | 21 |
* @requires Sarissa |
19 |
*
|
|
22 |
* |
|
20 | 23 |
*/ |
21 | 24 |
function OwsContext(modelNode, parent) { |
22 | 25 |
// Inherit the ModelBase functions and parameters |
23 | 26 |
ModelBase.apply(this, new Array(modelNode, parent)); |
24 | 27 |
|
25 |
this.namespace = "xmlns:wmc='http://www.opengis.net/context' xmlns:ows='http://www.opengis.net/ows' xmlns:ogc='http://www.opengis.net/ogc' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:xlink='http://www.w3.org/1999/xlink'"; |
|
28 |
// MAP-186 |
|
29 |
this.namespace = this.namespace ? this.namespace.replace(/\"/g, "'")+" " : ''; |
|
30 |
this.namespace = this.namespace + "xmlns:wmc='http://www.opengis.net/context' xmlns:ows='http://www.opengis.net/ows' xmlns:ogc='http://www.opengis.net/ogc' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:gml='http://www.opengis.net/gml' xmlns:wfs='http://www.opengis.net/wfs' xmlns:sld='http://www.opengis.net/sld'"; |
|
26 | 31 |
|
27 |
// =============================== |
|
28 |
// Update of Context Parameters |
|
29 |
// =============================== |
|
30 |
|
|
31 | 32 |
/** |
32 | 33 |
* Change a Layer's visibility. |
33 |
* @param layerName The name of the layer that is to be changed
|
|
34 |
* @param layerId The name of the layer that is to be changed
|
|
34 | 35 |
* @param hidden String with the value to be set; 1=hidden, 0=visible. |
35 | 36 |
*/ |
36 |
this.setHidden=function(layerName, hidden){
|
|
37 |
this.setHidden=function(layerId, hidden){
|
|
37 | 38 |
// Set the hidden attribute in the Context |
38 | 39 |
var hiddenValue = "0"; |
39 | 40 |
if (hidden) hiddenValue = "1"; |
40 |
|
|
41 |
var layer=this.getFeatureNode(layerName);
|
|
42 |
layer.setAttribute("hidden", hiddenValue); |
|
41 |
|
|
42 |
var layer=this.getLayer(layerId);
|
|
43 |
if (layer) layer.setAttribute("hidden", hiddenValue);
|
|
43 | 44 |
// Call the listeners |
44 |
this.callListeners("hidden", layerName);
|
|
45 |
this.callListeners("hidden", layerId);
|
|
45 | 46 |
} |
46 | 47 |
|
47 | 48 |
/** |
48 | 49 |
* Get the layer's visiblity attribute value. |
49 |
* @param layerName The name of the layer that is to be changed
|
|
50 |
* @param layerId The name of the layer that is to be changed
|
|
50 | 51 |
* @return hidden String with the value; 1=hidden, 0=visible. |
51 | 52 |
*/ |
52 |
this.getHidden=function(layerName){
|
|
53 |
this.getHidden=function(layerId){
|
|
53 | 54 |
var hidden=1; |
54 |
var layer=this.getFeatureNode(layerName) |
|
55 |
return layer.getAttribute("hidden"); |
|
55 |
var layer=this.getFeatureNode(layerId) |
|
56 |
if (layer) hidden = layer.getAttribute("hidden"); |
|
57 |
return hidden; |
|
56 | 58 |
} |
57 | 59 |
|
58 | 60 |
/** |
59 |
* Get the BoundingBox. |
|
60 |
* @return BoundingBox array in form (xmin,ymin,xmax,ymax).
|
|
61 |
* Get the BoundingBox value from the Context document.
|
|
62 |
* @return BoundingBox array with the sequence (xmin,ymin,xmax,ymax).
|
|
61 | 63 |
*/ |
62 | 64 |
this.getBoundingBox=function() { |
65 |
var bbox = new Array(); |
|
63 | 66 |
// Extract BoundingBox from the context |
64 |
//boundingBox=this.doc.documentElement.getElementsByTagName("BoundingBox").item(0); |
|
65 | 67 |
var lowerLeft=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/ows:BoundingBox/ows:LowerCorner"); |
66 | 68 |
var upperRight=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/ows:BoundingBox/ows:UpperCorner"); |
67 |
var strBbox = new String(lowerLeft.firstChild.nodeValue + " " + upperRight.firstChild.nodeValue).split(" "); |
|
68 |
var bbox = new Array(); |
|
69 |
var strBbox = new String(getNodeValue(lowerLeft) + " " + getNodeValue(upperRight)).split(" "); |
|
69 | 70 |
for (i=0; i<strBbox.length; ++i) { |
70 | 71 |
bbox[i] = parseFloat(strBbox[i]); |
71 | 72 |
} |
... | ... | |
83 | 84 |
var upperRight=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/ows:BoundingBox/ows:UpperCorner"); |
84 | 85 |
upperRight.firstChild.nodeValue = boundingBox[2] + " " + boundingBox[3]; |
85 | 86 |
// Call the listeners |
86 |
this.callListeners("bbox"); |
|
87 |
this.callListeners("bbox", boundingBox);
|
|
87 | 88 |
} |
88 | 89 |
|
89 | 90 |
/** |
90 |
* Set the Spacial Reference System for layer display and layer requests. |
|
91 |
* Set the BoundingBox element and call the refresh listeners |
|
92 |
* @param boundingBox array in the sequence (xmin, ymin, xmax, ymax). |
|
93 |
*/ |
|
94 |
this.initBbox=function(objRef) { |
|
95 |
// Set BoundingBox in context from URL CGI params |
|
96 |
if (window.cgiArgs["bbox"]) { //set as minx,miny,maxx,maxy |
|
97 |
var bbox = window.cgiArgs["bbox"].split(','); |
|
98 |
objRef.setBoundingBox(bbox); |
|
99 |
} |
|
100 |
} |
|
101 |
this.addListener( "loadModel", this.initBbox, this ); |
|
102 |
//this.addListener( "contextLoaded", this.initBbox, this ); |
|
103 |
|
|
104 |
/** |
|
105 |
* Set the aoi param and call the refresh listeners |
|
106 |
* @param boundingBox array in the sequence (xmin, ymin, xmax, ymax). |
|
107 |
*/ |
|
108 |
this.initAoi=function(objRef) { |
|
109 |
// Set AOI of context from URL CGI params |
|
110 |
if (window.cgiArgs["aoi"]) { //set as ul,lr point arrays |
|
111 |
var aoi = window.cgiArgs["aoi"].split(','); |
|
112 |
objRef.setParam("aoi",new Array(new Array(aoi[0],aoi[3]),new Array(aoi[2],aoi[1]))); |
|
113 |
} |
|
114 |
} |
|
115 |
this.addListener( "loadModel", this.initAoi, this ); |
|
116 |
//MA this.addListener( "contextLoaded", this.initAoi, this ); |
|
117 |
|
|
118 |
/** |
|
119 |
* Set the Spatial Reference System for the context document. |
|
91 | 120 |
* @param srs The Spatial Reference System. |
92 | 121 |
*/ |
93 | 122 |
this.setSRS=function(srs) { |
94 |
//bbox=this.doc.documentElement.getElementsByTagName("BoundingBox").item(0); |
|
95 | 123 |
var bbox=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/ows:BoundingBox"); |
96 | 124 |
bbox.setAttribute("crs",srs); |
97 | 125 |
this.callListeners("srs"); |
98 | 126 |
} |
99 | 127 |
|
100 | 128 |
/** |
101 |
* Set the Spacial Reference System for layer display and layer requests.
|
|
129 |
* Get the Spatial Reference System from the context document.
|
|
102 | 130 |
* @return srs The Spatial Reference System. |
103 | 131 |
*/ |
104 | 132 |
this.getSRS=function() { |
105 |
//bbox=this.doc.documentElement.getElementsByTagName("BoundingBox").item(0); |
|
106 | 133 |
var bbox=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/ows:BoundingBox"); |
107 | 134 |
srs=bbox.getAttribute("crs"); |
135 |
srs = srs ? srs : 'EPSG:4326'; |
|
108 | 136 |
return srs; |
109 | 137 |
} |
110 | 138 |
|
111 | 139 |
/** |
140 |
* Get the Projection object from the context document. |
|
141 |
* @return Proj Object of The Spatial Reference System. |
|
142 |
*/ |
|
143 |
this.initProj=function(objRef) { |
|
144 |
objRef.proj=new OpenLayers.Projection(objRef.getSRS()); |
|
145 |
} |
|
146 |
this.addFirstListener( "loadModel", this.initProj, this ); |
|
147 |
|
|
148 |
/** |
|
112 | 149 |
* Get the Window width. |
113 | 150 |
* @return width The width of map window from the context document |
114 | 151 |
*/ |
115 | 152 |
this.getWindowWidth=function() { |
116 |
//var win=this.doc.documentElement.getElementsByTagName("Window").item(0); |
|
117 | 153 |
var win=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/wmc:Window"); |
118 |
width=win.getAttribute("width"); |
|
119 |
return width; |
|
154 |
return win.getAttribute("width"); |
|
120 | 155 |
} |
121 | 156 |
|
122 | 157 |
/** |
123 | 158 |
* Set the Window width. |
124 |
* @param width The width of map window (therefore of map layer images).
|
|
159 |
* @param width The width of map window to set in the context document
|
|
125 | 160 |
*/ |
126 | 161 |
this.setWindowWidth=function(width) { |
127 |
//win=this.doc.documentElement.getElementsByTagName("Window").item(0); |
|
128 | 162 |
var win=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/wmc:Window"); |
129 | 163 |
win.setAttribute("width", width); |
130 | 164 |
this.callListeners("resize"); |
... | ... | |
135 | 169 |
* @return height The height of map window from the context document. |
136 | 170 |
*/ |
137 | 171 |
this.getWindowHeight=function() { |
138 |
//var win=this.doc.documentElement.getElementsByTagName("Window").item(0); |
|
139 | 172 |
var win=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/wmc:Window"); |
140 |
height=win.getAttribute("height"); |
|
141 |
return height; |
|
173 |
return win.getAttribute("height"); |
|
142 | 174 |
} |
143 | 175 |
|
144 | 176 |
/** |
145 | 177 |
* Set the Window height. |
146 |
* @param height The height of map window (therefore of map layer images).
|
|
178 |
* @param height The height of map window to set in the context document
|
|
147 | 179 |
*/ |
148 | 180 |
this.setWindowHeight=function(height) { |
149 |
//win=this.doc.documentElement.getElementsByTagName("Window").item(0); |
|
150 | 181 |
var win=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/wmc:Window"); |
151 | 182 |
win.setAttribute("height", height); |
152 | 183 |
this.callListeners("resize"); |
153 | 184 |
} |
154 | 185 |
|
155 | 186 |
/** |
187 |
* Returns the width/height of the map window as an array |
|
188 |
* Added by Andreas Hocevar for compatibility with Context.js |
|
189 |
*/ |
|
190 |
this.getWindowSize=function() { |
|
191 |
var win=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/wmc:Window"); |
|
192 |
return new Array(win.getAttribute("width"), win.getAttribute("height")); |
|
193 |
} |
|
194 |
|
|
195 |
/** |
|
196 |
* Set the Window width and height in one function call to avoid a resize event in between |
|
197 |
* setting width and height, because that causes checkBbox to be triggered, which adjusts the |
|
198 |
* bbox then when it should not yet be adjusted. |
|
199 |
* Based on setWindowSize by VTS in Context.js |
|
200 |
* Added by Andreas Hocevar for compatibility with Context.js |
|
201 |
* @param size Size of the map window as (width, height) array |
|
202 |
*/ |
|
203 |
this.setWindowSize=function(size) { |
|
204 |
var win=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/wmc:Window"); |
|
205 |
var width = size[0]; |
|
206 |
var height = size[1]; |
|
207 |
win.setAttribute("width", width); |
|
208 |
win.setAttribute("height", height); |
|
209 |
this.callListeners("resize"); |
|
210 |
} |
|
211 |
|
|
212 |
/** |
|
213 |
* returns a node that has the specified feature name in the context doc |
|
214 |
* @param featureName Name element value to return |
|
215 |
* @return the node from the context doc with the specified feature name |
|
216 |
*/ |
|
217 |
this.getFeatureNode = function(layerId) { |
|
218 |
if( this.doc ) { |
|
219 |
|
|
220 |
// Find feature by id |
|
221 |
var feature = this.doc.selectSingleNode("//wmc:ResourceList/*[@id='"+layerId+"']"); |
|
222 |
|
|
223 |
// Fallback: find feature by name |
|
224 |
if (feature == null) { |
|
225 |
feature = this.doc.selectSingleNode("//wmc:ResourceList/*[wmc:Name='"+layerId+"']"); |
|
226 |
} |
|
227 |
|
|
228 |
if(feature == null ) { |
|
229 |
alert(mbGetMessage("featureNotFoundOwsContext")); |
|
230 |
} |
|
231 |
|
|
232 |
return feature; |
|
233 |
} |
|
234 |
} |
|
235 |
|
|
236 |
/** |
|
156 | 237 |
* Returns the serverUrl for the layer passed in as the feature argument. |
157 | 238 |
* @param requestName ignored for context docs (only GetMap supported) |
158 | 239 |
* @param method ignored for context docs (only GET supported) |
... | ... | |
160 | 241 |
* @return height String URL for the GetMap request |
161 | 242 |
*/ |
162 | 243 |
this.getServerUrl = function(requestName, method, feature) { |
163 |
return feature.selectSingleNode("wmc:Server/wmc:OnlineResource").getAttribute("xlink:href"); |
|
244 |
var service = requestName.split(":"); |
|
245 |
if (service.length > 0) { |
|
246 |
service = service[0].toUpperCase(); |
|
247 |
} |
|
248 |
var url = feature.selectSingleNode("wmc:Server[@service='OGC:"+service+"']/wmc:OnlineResource").getAttribute("xlink:href"); |
|
249 |
if (!url) { |
|
250 |
// fallback to default service |
|
251 |
url = feature.selectSingleNode("wmc:Server/wmc:OnlineResource").getAttribute("xlink:href"); |
|
252 |
} |
|
253 |
return url; |
|
164 | 254 |
} |
165 | 255 |
|
166 | 256 |
/** |
... | ... | |
168 | 258 |
* @param feature the node for the feature from the context doc |
169 | 259 |
* @return the WMS GetMap version for the Layer. |
170 | 260 |
*/ |
171 |
this.getVersion = function(feature) {
|
|
261 |
this.getVersion = function(feature) { |
|
172 | 262 |
return feature.selectSingleNode("wmc:Server").getAttribute("version"); |
173 | 263 |
} |
174 | 264 |
|
... | ... | |
182 | 272 |
} |
183 | 273 |
|
184 | 274 |
/** |
185 |
* returns a node that has the specified feature name in the context doc |
|
186 |
* @param featureName Name element value to return |
|
187 |
* @return the node from the context doc with the specified feature name |
|
275 |
* Return the service type of the bottom layer in the layer list. |
|
276 |
* This is used to match navigation tools with the basemap. |
|
188 | 277 |
*/ |
189 |
this.getFeatureNode = function(featureName) { |
|
190 |
return this.doc.selectSingleNode(this.nodeSelectXpath+"/*[wmc:Name='"+featureName+"']"); |
|
278 |
this.getBaseLayerService=function(){ |
|
279 |
//x=this.doc.selectSingleNode("/wmc:OWSContext/wmc:ResourceList/wmc:Layer[last()]/wmc:Server/@service"); |
|
280 |
x=this.doc.selectSingleNode("/wmc:OWSContext/wmc:ResourceList/wmc:Layer[last()]/wmc:Server"); |
|
281 |
s=x.getAttribute("service"); |
|
282 |
//alert("OwsContext.getBaseLayerService: s="+s); |
|
283 |
return s; |
|
191 | 284 |
} |
192 | 285 |
|
193 | 286 |
/** |
194 |
* listener method which loads WFS features from the context doc, after WMS
|
|
287 |
* listener method which loads WFS features from the context doc, after WMS |
|
195 | 288 |
* layers are loaded. |
196 | 289 |
* @param objRef Pointer to this object. |
197 | 290 |
*/ |
... | ... | |
199 | 292 |
var nodeSelectXpath = objRef.nodeSelectXpath + "/wmc:FeatureType[wmc:Server/@service='OGC:WFS']/wmc:Name"; |
200 | 293 |
var featureList = objRef.doc.selectNodes(nodeSelectXpath); |
201 | 294 |
for (var i=0; i<featureList.length; i++) { |
202 |
var featureName = featureList[i].firstChild.nodeValue;
|
|
295 |
var featureName = getNodeValue(featureList[i]);
|
|
203 | 296 |
objRef.setParam('wfs_GetFeature',featureName); |
204 | 297 |
} |
298 |
|
|
299 |
//this.callListeners("contextLoaded"); //PGC |
|
205 | 300 |
} |
206 | 301 |
this.addListener("loadModel", this.loadFeatures, this); |
207 | 302 |
|
... | ... | |
213 | 308 |
this.setRequestParameters = function(featureName, requestStylesheet) { |
214 | 309 |
var feature = this.getFeatureNode(featureName); |
215 | 310 |
if (feature.selectSingleNode("ogc:Filter")) { |
216 |
requestStylesheet.setParameter("filter", escape(Sarissa.serialize(feature.selectSingleNode("ogc:Filter"))) );
|
|
311 |
requestStylesheet.setParameter("filter", escape((new XMLSerializer()).serializeToString(feature.selectSingleNode("ogc:Filter"))) );
|
|
217 | 312 |
} |
218 | 313 |
} |
219 | 314 |
//this.addFirstListener("wfs_GetFeature", this.setRequestParameters, this); |
... | ... | |
223 | 318 |
* @return the list with queryable layers |
224 | 319 |
*/ |
225 | 320 |
this.getQueryableLayers = function() { |
226 |
var listNodeArray = this.doc.selectNodes("/wmc:OWSContext/wmc:ResourceList/wmc:Layer[attribute::queryable='1']/wmc:Name"); |
|
321 |
var listNodeArray = this.doc.selectNodes("/wmc:OWSContext/wmc:ResourceList/wmc:Layer[@queryable='1']|/wmc:OWSContext/wmc:ResourceList/wmc:FeatureType[@queryable='1']"); |
|
322 |
if (listNodeArray == null) { |
|
323 |
listNodeArray = this.doc.selectNodes("/wmc:OWSContext/wmc:ResourceList/wmc:Layer|/wmc:OWSContext/wmc:ResourceList/wmc:Layer"); |
|
324 |
} |
|
227 | 325 |
return listNodeArray; |
228 | 326 |
} |
229 | 327 |
|
230 | 328 |
/** |
231 | 329 |
* Method to get a list of all layers in the context doc |
232 | 330 |
* TBD: merge this with above, passing queryable as an optional boolean param? |
331 |
* @TODO Add the other layers |
|
233 | 332 |
* @return the list with all layers |
234 | 333 |
*/ |
235 | 334 |
this.getAllLayers = function() { |
236 |
var listNodeArray = this.doc.selectNodes("/wmc:OWSContext/wmc:ResourceList/wmc:Layer");
|
|
335 |
var listNodeArray = this.doc.selectNodes("//wmc:Layer|//wmc:FeatureType");
|
|
237 | 336 |
return listNodeArray; |
238 | 337 |
} |
239 | 338 |
|
240 | 339 |
/** |
241 |
* Method to get a layer with the specified name in the context doc |
|
242 |
* @param layerName the layer to be returned |
|
340 |
* Method to get a layer with the specified id/name in the context doc
|
|
341 |
* @param layerId/layerName the layer to be returned
|
|
243 | 342 |
* @return the list with all layers |
343 |
* @TODO check other layers |
|
244 | 344 |
*/ |
245 |
this.getLayer = function(layerName) { |
|
246 |
var layer = this.doc.selectSingleNode("/wmc:OWSContext/wmc:ResourceList/wmc:Layer[wmc:Name='"+layerName+"']"); |
|
345 |
this.getLayer = function(layerId) { |
|
346 |
var layer = this.doc.selectSingleNode("/wmc:OWSContext/wmc:ResourceList/wmc:FeatureType[@id='"+layerId+"']"); |
|
347 |
if (layer == null) { |
|
348 |
layer = this.doc.selectSingleNode("/wmc:OWSContext/wmc:ResourceList/wmc:Layer[@id='"+layerId+"']"); |
|
349 |
} |
|
350 |
if (layer == null) { |
|
351 |
layer = this.doc.selectSingleNode("/wmc:OWSContext/wmc:ResourceList/wmc:Layer[wmc:Name='"+layerId+"']"); |
|
352 |
} |
|
353 |
if (layer == null) { |
|
354 |
layer = this.doc.selectSingleNode("/wmc:OWSContext/wmc:ResourceList/wmc:FeatureType[wmc:Name='"+layerId+"']"); |
|
355 |
} |
|
356 |
if( layer == null ) { |
|
357 |
layer = this.doc.selectSingleNode("/wmc:OWSContext/wmc:ResourceList/wmc:RssLayer[@id='"+layerId+"']"); |
|
358 |
} |
|
247 | 359 |
//TBD: add in time stamp |
248 | 360 |
return layer; |
249 | 361 |
} |
250 | 362 |
|
363 |
/** |
|
364 |
* Method to get a layer id with the specified id/name in the context doc |
|
365 |
* @param layerName the name of the layer of which the id is to be returned |
|
366 |
* @return the id of the layer || false |
|
367 |
*/ |
|
368 |
this.getLayerIdByName = function(layerName) { |
|
369 |
var layer = this.getLayer(layerName); |
|
370 |
var id; |
|
371 |
if (layer) { |
|
372 |
id = layer.getAttribute("id"); |
|
373 |
} |
|
251 | 374 |
|
375 |
return id || false; |
|
376 |
} |
|
377 |
|
|
378 |
|
|
379 |
/** |
|
380 |
* Method to add a Layer to the LayerList |
|
381 |
* @param layerNode the Layer node from another context doc or capabiltiies doc |
|
382 |
*/ |
|
383 |
this.addLayer = function(objRef, layerNode) { |
|
384 |
if( objRef.doc != null ) { |
|
385 |
var parentNode = objRef.doc.selectSingleNode("/wmc:OWSContext/wmc:ResourceList"); |
|
386 |
|
|
387 |
// Generate layer id if layer doesn't have an id |
|
388 |
var randomNumber = Math.round(10000 * Math.random()); |
|
389 |
id = Mapbuilder.getProperty(layerNode, "wmc:Name") + "_" + randomNumber; |
|
390 |
layerNode.setAttribute("id", id); |
|
391 |
|
|
392 |
// check if that node does not alreayd exist, replace it (query may have changed) |
|
393 |
var id = layerNode.getAttribute("id"); |
|
394 |
var str = "/wmc:OWSContext/wmc:ResourceList/"+layerNode.nodeName+"[@id='"+id+"']"; |
|
395 |
var node = objRef.doc.selectSingleNode(str); |
|
396 |
if( node != null ) { |
|
397 |
parentNode.removeChild(node); |
|
398 |
} |
|
399 |
|
|
400 |
parentNode.appendChild(layerNode); |
|
401 |
objRef.modified = true; |
|
402 |
if (this.debug) { |
|
403 |
mbDebugMessage( "Adding layer:"+(new XMLSerializer()).serializeToString( layerNode ) ); |
|
404 |
} |
|
405 |
} else { |
|
406 |
alert(mbGetMessage("nullOwsContext")); |
|
407 |
} |
|
408 |
//objRef.callListeners("refresh"); |
|
409 |
} |
|
410 |
this.addFirstListener( "addLayer", this.addLayer, this ); |
|
411 |
|
|
412 |
/** |
|
413 |
* Method to get the baselayer |
|
414 |
* @return the baseLayer |
|
415 |
* @TODO check for other baselayers |
|
416 |
*/ |
|
417 |
this.getBaseLayer = function() { |
|
418 |
var baseLayer = this.doc.selectSingleNode("/wmc:OWSContext/wmc:ResourceList/ows:BaseLayer"); |
|
419 |
return baseLayer; |
|
420 |
} |
|
421 |
|
|
422 |
/** |
|
423 |
* Method to add a Sld to the StyleList |
|
424 |
* @param layerName the Layer name from another context doc or capabiltiies doc |
|
425 |
* TBD: make sure this will work again using layerId instead of layerName |
|
426 |
*/ |
|
427 |
this.addSLD = function(objRef,sldNode) { |
|
428 |
// alert("context addSLD : "+objRef.id); |
|
429 |
var layerName=Mapbuilder.getProperty(sldNode, "//Name"); |
|
430 |
var parentNode = objRef.doc.selectSingleNode("//wmc:Layer[wmc:Name='"+layerName+"']"); |
|
431 |
parentNode.appendChild(sldNode.cloneNode(true)); |
|
432 |
|
|
433 |
objRef.modified = true; |
|
434 |
var attribs=[]; |
|
435 |
attribs["sld_body"]=(new XMLSerializer()).serializeToString(objRef.doc.selectSingleNode("//wmc:Layer[wmc:Name='"+layerName+"']/wmc:StyleList/wmc:Style/wmc:SLD/wmc:StyledLayerDescriptor")); |
|
436 |
objRef.map.mbMapPane.refreshLayer(objRef.map.mbMapPane,layerName,attribs); |
|
437 |
} |
|
438 |
this.addFirstListener( "addSLD", this.addSLD, this ); |
|
439 |
|
|
440 |
/** |
|
441 |
* Method to remove a Layer from the LayerList |
|
442 |
* @param layerId the Layer to be deleted |
|
443 |
*/ |
|
444 |
this.deleteLayer = function(objRef, layerId) { |
|
445 |
var deletedNode = objRef.getLayer(layerId); |
|
446 |
if (!deletedNode) { |
|
447 |
alert(mbGetMessage("nodeNotFound", layerId)); |
|
448 |
return; |
|
449 |
} |
|
450 |
deletedNode.parentNode.removeChild(deletedNode); |
|
451 |
objRef.modified = true; |
|
452 |
} |
|
453 |
this.addFirstListener( "deleteLayer", this.deleteLayer, this ); |
|
454 |
|
|
455 |
/** |
|
456 |
* Method to move a Layer in the LayerList up |
|
457 |
* @param layerId the layer to be moved |
|
458 |
*/ |
|
459 |
this.moveLayerUp = function(objRef, layerId) { |
|
460 |
var movedNode = objRef.getLayer(layerId); |
|
461 |
var sibNode = movedNode.selectSingleNode("following-sibling::*"); |
|
462 |
if (!sibNode) { |
|
463 |
alert(mbGetMessage("cantMoveUp", layerId)); |
|
464 |
return; |
|
465 |
} |
|
466 |
movedNode.parentNode.insertBefore(sibNode,movedNode); |
|
467 |
objRef.modified = true; |
|
468 |
} |
|
469 |
this.addFirstListener( "moveLayerUp", this.moveLayerUp, this ); |
|
470 |
|
|
471 |
/** |
|
472 |
* Method to move a Layer in the LayerList down |
|
473 |
* @param layerId the layer to be moved |
|
474 |
*/ |
|
475 |
this.moveLayerDown = function(objRef, layerId) { |
|
476 |
var movedNode = objRef.getLayer(layerId); |
|
477 |
var listNodeArray = movedNode.selectNodes("preceding-sibling::*"); //preceding-sibling axis contains all previous siblings |
|
478 |
var sibNode = listNodeArray[listNodeArray.length-1]; |
|
479 |
if (!sibNode) { |
|
480 |
alert(mbGetMessage("cantMoveDown", layerId)); |
|
481 |
return; |
|
482 |
} |
|
483 |
movedNode.parentNode.insertBefore(movedNode,sibNode); |
|
484 |
objRef.modified = true; |
|
485 |
} |
|
486 |
this.addFirstListener( "moveLayerDown", this.moveLayerDown, this ); |
|
487 |
|
|
488 |
/** |
|
489 |
* Adds a node to the Context document extension element. The extension element |
|
490 |
* will be created if it doesn't already exist. |
|
491 |
* @param extensionNode the node to be appended in the extension element. |
|
492 |
* @return the ndoe added to the extension element |
|
493 |
*/ |
|
494 |
this.setExtension = function(extensionNode) { |
|
495 |
var extension = this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/wmc:Extension"); |
|
496 |
if (!extension) { |
|
497 |
var general = this.doc.selectSingleNode("/wmc:OWSContext/wmc:General"); |
|
498 |
var newChild = createElementWithNS(this.doc,"Extension",'http://www.opengis.net/context'); |
|
499 |
extension = general.appendChild(newChild); |
|
500 |
} |
|
501 |
return extension.appendChild(extensionNode); |
|
502 |
} |
|
503 |
|
|
504 |
/** |
|
505 |
* Returns the contents of the extension element |
|
506 |
* @return the contents of the extension element |
|
507 |
*/ |
|
508 |
this.getExtension = function() { |
|
509 |
return this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/wmc:Extension"); |
|
510 |
} |
|
511 |
|
|
512 |
// PL -BRGM |
|
513 |
/** |
|
514 |
* Change a Layer's opacity |
|
515 |
* @param layerId The name of the layer that is to be changed |
|
516 |
* @param Opacity Value of the opacity |
|
517 |
*/ |
|
518 |
this.setOpacity=function(layerId, Opacity){ |
|
519 |
// Set the hidden attribute in the Context |
|
520 |
var layer = this.getLayer(layerId); |
|
521 |
if (layer) layer.setAttribute("opacity", Opacity); |
|
522 |
// Call the listeners |
|
523 |
this.callListeners("opacity", layerId); |
|
524 |
} |
|
525 |
|
|
526 |
/** |
|
527 |
* Get the layer's opacity attribute value. |
|
528 |
* @param layerId The name of the layer that is to be changed |
|
529 |
* @return hidden String with the value; 1=hidden, 0=visible. |
|
530 |
*/ |
|
531 |
this.getOpacity=function(layerId){ |
|
532 |
var opacity=1; |
|
533 |
var layer = this.getLayer(layerId); |
|
534 |
if (layer) opacity = layer.getAttribute("opacity"); |
|
535 |
return opacity; |
|
536 |
} |
|
537 |
// PL -END |
|
538 |
|
|
539 |
/** |
|
540 |
* Parses a Dimension element from the Context document as a loadModel listener. |
|
541 |
* This results in an XML structure with one element for each GetMap time value |
|
542 |
* parameter and added to the Context extrension element. |
|
543 |
* @param objRef a pointer to this object |
|
544 |
*/ |
|
545 |
this.initTimeExtent = function( objRef ) { |
|
546 |
//only the first one selected is used as the timestamp source |
|
547 |
//var extentNode = objRef.doc.selectSingleNode("//wmc:Layer/wmc:Dimension[@name='time']"); |
|
548 |
//TBD: how to deal with multiple time dimensions in one context doc, or caps doc? |
|
549 |
var timeNodes = objRef.doc.selectNodes("//wmc:Dimension[@name='time']"); |
|
550 |
for (var i=0; i<timeNodes.length; ++i) { |
|
551 |
var extentNode = timeNodes[i]; |
|
552 |
objRef.timestampList = createElementWithNS(objRef.doc,"TimestampList",mbNsUrl); |
|
553 |
var layerId; |
|
554 |
var layerNode = extentNode.parentNode.parentNode; |
|
555 |
if (layerNode.selectSingleNode("@id")) { |
|
556 |
layerId = Mapbuilder.getProperty(layerNode, "@id"); |
|
557 |
} else { |
|
558 |
layerId =Mapbuilder.getProperty(layerNode, "wmc:Name"); |
|
559 |
} |
|
560 |
objRef.timestampList.setAttribute("layerId", layerId); |
|
561 |
//alert("found time dimension, extent:"+getNodeValue(extentNode)); |
|
562 |
var times = getNodeValue(extentNode).split(","); //comma separated list of arguments |
|
563 |
for (var j=0; j<times.length; ++j) { |
|
564 |
var params = times[j].split("/"); // parses start/end/period |
|
565 |
if (params.length==3) { |
|
566 |
var start = setISODate(params[0]); |
|
567 |
var stop = setISODate(params[1]); |
|
568 |
var period = params[2]; |
|
569 |
var parts = period.match(/^P((\d*)Y)?((\d*)M)?((\d*)D)?T?((\d*)H)?((\d*)M)?((.*)S)?/); |
|
570 |
for (var i=1; i<parts.length; ++i) { |
|
571 |
if (!parts[i]) parts[i]=0; |
|
572 |
} |
|
573 |
//alert("start time:"+start.toString()); |
|
574 |
do { |
|
575 |
var timestamp = createElementWithNS(objRef.doc,"Timestamp",mbNsUrl); |
|
576 |
timestamp.appendChild(objRef.doc.createTextNode(getISODate(start))); |
|
577 |
objRef.timestampList.appendChild(timestamp); |
|
578 |
|
|
579 |
start.setFullYear(start.getFullYear()+parseInt(parts[2],10)); |
|
580 |
start.setMonth(start.getMonth()+parseInt(parts[4],10)); |
|
581 |
start.setDate(start.getDate()+parseInt(parts[6],10)); |
|
582 |
start.setHours(start.getHours()+parseInt(parts[8],10)); |
|
583 |
start.setMinutes(start.getMinutes()+parseInt(parts[10],10)); |
|
584 |
start.setSeconds(start.getSeconds()+parseFloat(parts[12])); |
|
585 |
//alert("time:"+start.toString()); |
|
586 |
} while(start.getTime() <= stop.getTime()); |
|
587 |
|
|
588 |
} else { |
|
589 |
//output single date value |
|
590 |
var timestamp = createElementWithNS(objRef.doc,"Timestamp",mbNsUrl); |
|
591 |
timestamp.appendChild(objRef.doc.createTextNode(times[j])); |
|
592 |
objRef.timestampList.appendChild(timestamp); |
|
593 |
} |
|
594 |
} |
|
595 |
objRef.setExtension(objRef.timestampList); |
|
596 |
} |
|
597 |
} |
|
598 |
this.addFirstListener( "loadModel", this.initTimeExtent, this ); |
|
599 |
|
|
600 |
/** |
|
601 |
* clear the time extent created by initTimeExtent |
|
602 |
* @param objRef reference to this model |
|
603 |
*/ |
|
604 |
this.clearTimeExtent = function( objRef ) { |
|
605 |
var tsList = objRef.timestampList; |
|
606 |
if (tsList) { |
|
607 |
tsList.parentNode.removeChild(tsList); |
|
608 |
} |
|
609 |
} |
|
610 |
this.addListener("newModel", this.clearTimeExtent, this); |
|
611 |
|
|
612 |
/** |
|
613 |
* Returns the current timestamp value. |
|
614 |
* @param layerName the name of the Layer from which the timestamp list was generated |
|
615 |
* @return the current timestamp value. |
|
616 |
*/ |
|
617 |
this.getCurrentTimestamp = function( layerName ) { |
|
618 |
var index = this.getParam("timestamp"); |
|
619 |
return getNodeValue(this.timestampList.childNodes[index]); |
|
620 |
} |
|
621 |
|
|
252 | 622 |
} |
253 |
|
Also available in: Unified diff
upgrade to MapBuilder 1.5rc2 - includes support for Firefox 3 compatibility (yes, it is also EOLed)