Project

General

Profile

1
<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
2
<html>
3
<head>
4
<title>
5
<a href='http://mapbuilder.sourceforge.net'>Community Map Builder</a> 27 Apr 2008 Overview
6
</title>
7
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
8
<script>
9
function asd() {
10
	
11
		parent.document.title="OwsContext.js Overview";
12
	
13
}
14
</script>
15
</head>
16
<body bgcolor="white" onload="asd();">
17

    
18
<!-- ========== START OF NAVBAR ========== -->
19
<a name="navbar_top"><!-- --></a>
20
<table border="0" width="100%" cellpadding="1" cellspacing="0">
21
<tr>
22
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
23
<a name="navbar_top_firstrow"><!-- --></a>
24
<table border="0" cellpadding="0" cellspacing="3">
25
  <tr align="center" valign="top">
26
  
27
  
28
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
29
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
30
  
31

    
32
  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
33
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
34
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
35
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
36
  </tr>
37
</table>
38
</td>
39
<td bgcolor="#EEEEFF" align="right" valign="top">
40
<em>
41
<b><a href='http://mapbuilder.sourceforge.net'>Community Map Builder</a> 27 Apr 2008</b></em>
42
</td>
43
</tr>
44

    
45
<tr>
46
<td bgcolor="white" class="NavBarCell2"><font size="-2">
47
&nbsp;PREV&nbsp;
48
&nbsp;NEXT</font></td>
49
<td bgcolor="white" class="NavBarCell2"><font size="-2">
50
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
51
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
52
&nbsp;&nbsp;
53
<script>
54
  <!--
55
  if(window==top) {
56
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
57
  }
58
  //-->
59
</script>
60
<noscript>
61
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
62
</noscript>
63
</font></td>
64
</tr>
65
</table>
66
<!-- =========== END OF NAVBAR =========== -->
67

    
68
<hr>
69
<center>
70
	
71
	   <h2>OwsContext.js</h2>
72
	
73
</center>
74

    
75
	
76

    
77

    
78
<h4>Summary</h4>
79
<p>
80
	
81
		No overview generated for 'OwsContext.js'<BR/><BR/>
82
	
83
</p>
84

    
85
<hr>
86

    
87

    
88
    <table border="1" cellpadding="3" cellspacing="0" width="100%">
89
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
90
    <td colspan=2><font size="+2">
91
    
92
        <b>Class Summary</b>
93
    
94
    </font></td>
95
    </tr>
96
    
97
    <tr bgcolor="white" class="TableRowColor">
98
    <td width="15%"><b><a href="OwsContext.html">OwsContext</a></b></td>
99
    <td>&nbsp;</td>
100
    </tr>
101
    
102
    </table>
103
    <hr/> 
104

    
105

    
106
<!-- ========== METHOD SUMMARY =========== -->
107

    
108
<!-- ========== END METHOD SUMMARY =========== -->
109

    
110

    
111
        <pre class="sourceview"><span class="comment">/*
112
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
113
$Id: OwsContext.js 3887 2008-02-27 18:18:53Z ahocevar $
114
*/</span>
115
<span class="comment">
116
// Ensure this object's dependancies are loaded.</span>
117
mapbuilder.loadScript(baseDir+<span class="literal">"/model/ModelBase.js"</span>);
118

    
119
<span class="comment">/**
120
 * Stores an OWS Context document as defined by the OGC interoperability
121
 * experiment. This model should be eventually merged with the standard OGC
122
 * context doc.
123
 * Listeners supported by this model:
124
 * "refresh" called when window parameters (width/height, bbox) are changed
125
 * "hidden" called when visibilty of a layer is changed
126
 * "wfs_getFeature" called when feature resources are loaded
127
 *
128
 * <span class="attrib">@constructor</span>
129
 * <span class="attrib">@base</span> ModelBase
130
 * <span class="attrib">@author</span> Mike Adair
131
 * <span class="attrib">@requires</span> Sarissa
132
 *
133
 */</span>
134
<span class="reserved">function</span> OwsContext(modelNode, parent) {
135
<span class="comment">  // Inherit the ModelBase functions and parameters</span>
136
  ModelBase.apply(<span class="reserved">this</span>, new Array(modelNode, parent));
137
<span class="comment">
138
  // MAP-186</span>
139
  <span class="reserved">this</span>.namespace = <span class="reserved">this</span>.namespace ? <span class="reserved">this</span>.namespace.replace(/\<span class="literal">"/g, "</span><span class="literal">'")+" " : '</span><span class="literal">';
140
  this.namespace = this.namespace + "xmlns:wmc='</span>http://www.opengis.net/context<span class="literal">' xmlns:ows='</span>http://www.opengis.net/ows<span class="literal">' xmlns:ogc='</span>http://www.opengis.net/ogc<span class="literal">' xmlns:xsl='</span>http://www.w3.org/1999/XSL/Transform<span class="literal">' xmlns:xlink='</span>http://www.w3.org/1999/xlink<span class="literal">' xmlns:gml='</span>http://www.opengis.net/gml<span class="literal">' xmlns:wfs='</span>http://www.opengis.net/wfs<span class="literal">' xmlns:sld='</span>http://www.opengis.net/sld<span class="literal">'";
141

    
142
  /**
143
   * Change a Layer'</span>s visibility.
144
   * @param layerId  The name of the layer that is to be changed
145
   * @param hidden     String with the value to be set; 1=hidden, 0=visible.
146
   */
147
  <span class="reserved">this</span>.setHidden=<span class="reserved">function</span>(layerId, hidden){
148
<span class="comment">    // Set the hidden attribute in the Context</span>
149
    var hiddenValue = <span class="literal">"0"</span>;
150
    <span class="reserved">if</span> (hidden) hiddenValue = <span class="literal">"1"</span>;
151

    
152
    var layer=<span class="reserved">this</span>.getLayer(layerId);
153
    <span class="reserved">if</span> (layer) layer.setAttribute(<span class="literal">"hidden"</span>, hiddenValue);
154
<span class="comment">    // Call the listeners</span>
155
    <span class="reserved">this</span>.callListeners(<span class="literal">"hidden"</span>, layerId);
156
  }
157

    
158
  <span class="comment">/**
159
   * Get the layer's visiblity attribute value.
160
   * <span class="attrib">@param</span> layerId  The name of the layer that is to be changed
161
   * <span class="attrib">@return</span> hidden  String with the value; 1=hidden, 0=visible.
162
   */</span>
163
  <span class="reserved">this</span>.getHidden=<span class="reserved">function</span>(layerId){
164
    var hidden=1;
165
    var layer=<span class="reserved">this</span>.getFeatureNode(layerId)
166
    <span class="reserved">if</span> (layer) hidden = layer.getAttribute(<span class="literal">"hidden"</span>);
167
    <span class="reserved">return</span> hidden;
168
  }
169

    
170
  <span class="comment">/**
171
   * Get the BoundingBox value from the Context document.
172
   * <span class="attrib">@return</span> BoundingBox array with the sequence (xmin,ymin,xmax,ymax).
173
   */</span>
174
  <span class="reserved">this</span>.getBoundingBox=<span class="reserved">function</span>() {
175
    var bbox = new Array();
176
<span class="comment">    // Extract BoundingBox from the context</span>
177
    var lowerLeft=<span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:General/ows:BoundingBox/ows:LowerCorner"</span>);
178
    var upperRight=<span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:General/ows:BoundingBox/ows:UpperCorner"</span>);
179
    var strBbox = new String(getNodeValue(lowerLeft) + <span class="literal">" "</span> + getNodeValue(upperRight)).split(<span class="literal">" "</span>);
180
    <span class="reserved">for</span> (i=0; i&lt;strBbox.length; ++i) {
181
      bbox[i] = parseFloat(strBbox[i]);
182
    }
183
    <span class="reserved">return</span> bbox;
184
  }
185

    
186
  <span class="comment">/**
187
   * Set the BoundingBox element and call the refresh listeners
188
   * <span class="attrib">@param</span> boundingBox array in the sequence (xmin, ymin, xmax, ymax).
189
   */</span>
190
  <span class="reserved">this</span>.setBoundingBox=<span class="reserved">function</span>(boundingBox) {
191
<span class="comment">    // Set BoundingBox in context</span>
192
    var lowerLeft=<span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:General/ows:BoundingBox/ows:LowerCorner"</span>);
193
    lowerLeft.firstChild.nodeValue = boundingBox[0] + <span class="literal">" "</span> + boundingBox[1];
194
    var upperRight=<span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:General/ows:BoundingBox/ows:UpperCorner"</span>);
195
    upperRight.firstChild.nodeValue = boundingBox[2] + <span class="literal">" "</span> + boundingBox[3];
196
<span class="comment">    // Call the listeners</span>
197
    <span class="reserved">this</span>.callListeners(<span class="literal">"bbox"</span>, boundingBox);
198
  }
199

    
200
  <span class="comment">/**
201
   * Set the BoundingBox element and call the refresh listeners
202
   * <span class="attrib">@param</span> boundingBox array in the sequence (xmin, ymin, xmax, ymax).
203
   */</span>
204
  <span class="reserved">this</span>.initBbox=<span class="reserved">function</span>(objRef) {
205
<span class="comment">    // Set BoundingBox in context from URL CGI params</span>
206
    <span class="reserved">if</span> (window.cgiArgs[<span class="literal">"bbox"</span>]) {   //set as minx,miny,maxx,maxy
207
      var bbox = window.cgiArgs[<span class="literal">"bbox"</span>].split(<span class="literal">','</span>);
208
      objRef.setBoundingBox(bbox);
209
    }
210
  }
211
  <span class="reserved">this</span>.addListener( <span class="literal">"loadModel"</span>, <span class="reserved">this</span>.initBbox, <span class="reserved">this</span> );
212
<span class="comment">  //this.addListener( "contextLoaded", this.initBbox, this );</span>
213

    
214
  <span class="comment">/**
215
   * Set the aoi param and call the refresh listeners
216
   * <span class="attrib">@param</span> boundingBox array in the sequence (xmin, ymin, xmax, ymax).
217
   */</span>
218
  <span class="reserved">this</span>.initAoi=<span class="reserved">function</span>(objRef) {
219
<span class="comment">    // Set AOI of context from URL CGI params</span>
220
    <span class="reserved">if</span> (window.cgiArgs[<span class="literal">"aoi"</span>]) {      //set as ul,lr point arrays
221
      var aoi = window.cgiArgs[<span class="literal">"aoi"</span>].split(<span class="literal">','</span>);
222
      objRef.setParam(<span class="literal">"aoi"</span>,new Array(new Array(aoi[0],aoi[3]),new Array(aoi[2],aoi[1])));
223
    }
224
  }
225
  <span class="reserved">this</span>.addListener( <span class="literal">"loadModel"</span>, <span class="reserved">this</span>.initAoi, <span class="reserved">this</span> );
226
<span class="comment">  //MA this.addListener( "contextLoaded", this.initAoi, this );</span>
227

    
228
  <span class="comment">/**
229
   * Set the Spatial Reference System for the context document.
230
   * <span class="attrib">@param</span> srs The Spatial Reference System.
231
   */</span>
232
  <span class="reserved">this</span>.setSRS=<span class="reserved">function</span>(srs) {
233
    var bbox=<span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:General/ows:BoundingBox"</span>);
234
    bbox.setAttribute(<span class="literal">"crs"</span>,srs);
235
    <span class="reserved">this</span>.callListeners(<span class="literal">"srs"</span>);
236
  }
237

    
238
  <span class="comment">/**
239
   * Get the Spatial Reference System from the context document.
240
   * <span class="attrib">@return</span> srs The Spatial Reference System.
241
   */</span>
242
  <span class="reserved">this</span>.getSRS=<span class="reserved">function</span>() {
243
    var bbox=<span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:General/ows:BoundingBox"</span>);
244
    srs=bbox.getAttribute(<span class="literal">"crs"</span>);
245
    srs = srs ? srs : <span class="literal">'EPSG:4326'</span>;
246
    <span class="reserved">return</span> srs;
247
  }
248

    
249
  <span class="comment">/**
250
   * Get the Projection object from the context document.
251
   * <span class="attrib">@return</span> Proj Object of  The Spatial Reference System.
252
   */</span>
253
  <span class="reserved">this</span>.initProj=<span class="reserved">function</span>(objRef) {
254
    objRef.proj=new OpenLayers.Projection(objRef.getSRS());
255
  }
256
  <span class="reserved">this</span>.addFirstListener( <span class="literal">"loadModel"</span>, <span class="reserved">this</span>.initProj, <span class="reserved">this</span> );
257

    
258
  <span class="comment">/**
259
   * Get the Window width.
260
   * <span class="attrib">@return</span> width The width of map window from the context document
261
   */</span>
262
  <span class="reserved">this</span>.getWindowWidth=<span class="reserved">function</span>() {
263
    var win=<span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:General/wmc:Window"</span>);
264
    <span class="reserved">return</span> win.getAttribute(<span class="literal">"width"</span>);
265
  }
266

    
267
  <span class="comment">/**
268
   * Set the Window width.
269
   * <span class="attrib">@param</span> width The width of map window to set in the context document
270
   */</span>
271
  <span class="reserved">this</span>.setWindowWidth=<span class="reserved">function</span>(width) {
272
    var win=<span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:General/wmc:Window"</span>);
273
    win.setAttribute(<span class="literal">"width"</span>, width);
274
    <span class="reserved">this</span>.callListeners(<span class="literal">"resize"</span>);
275
  }
276

    
277
  <span class="comment">/**
278
   * Get the Window height.
279
   * <span class="attrib">@return</span> height The height of map window from the context document.
280
   */</span>
281
  <span class="reserved">this</span>.getWindowHeight=<span class="reserved">function</span>() {
282
    var win=<span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:General/wmc:Window"</span>);
283
    <span class="reserved">return</span> win.getAttribute(<span class="literal">"height"</span>);
284
  }
285

    
286
  <span class="comment">/**
287
   * Set the Window height.
288
   * <span class="attrib">@param</span> height The height of map window to set in the context document
289
   */</span>
290
  <span class="reserved">this</span>.setWindowHeight=<span class="reserved">function</span>(height) {
291
    var win=<span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:General/wmc:Window"</span>);
292
    win.setAttribute(<span class="literal">"height"</span>, height);
293
    <span class="reserved">this</span>.callListeners(<span class="literal">"resize"</span>);
294
  }
295

    
296
  <span class="comment">/**
297
   * Returns the width/height of the map window as an array
298
   * Added by Andreas Hocevar for compatibility with Context.js
299
   */</span>
300
  <span class="reserved">this</span>.getWindowSize=<span class="reserved">function</span>() {
301
    var win=<span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:General/wmc:Window"</span>);
302
    <span class="reserved">return</span> new Array(win.getAttribute(<span class="literal">"width"</span>), win.getAttribute(<span class="literal">"height"</span>));
303
  }
304

    
305
  <span class="comment">/**
306
   * Set the Window width and height in one function call to avoid a resize event in between
307
   * setting width and height, because that causes checkBbox to be triggered, which adjusts the
308
   * bbox then when it should not yet be adjusted.
309
   * Based on setWindowSize by VTS in Context.js
310
   * Added by Andreas Hocevar for compatibility with Context.js
311
   * <span class="attrib">@param</span> size Size of the map window as (width, height) array
312
   */</span>
313
  <span class="reserved">this</span>.setWindowSize=<span class="reserved">function</span>(size) {
314
    var win=<span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:General/wmc:Window"</span>);
315
    var width = size[0];
316
    var height = size[1];
317
    win.setAttribute(<span class="literal">"width"</span>, width);
318
    win.setAttribute(<span class="literal">"height"</span>, height);
319
    <span class="reserved">this</span>.callListeners(<span class="literal">"resize"</span>);
320
  }
321

    
322
  <span class="comment">/**
323
   * returns a node that has the specified feature name in the context doc
324
   * <span class="attrib">@param</span> featureName Name element value to return
325
   * <span class="attrib">@return</span> the node from the context doc with the specified feature name
326
   */</span>
327
  <span class="reserved">this</span>.getFeatureNode = <span class="reserved">function</span>(layerId) {
328
    <span class="reserved">if</span>( <span class="reserved">this</span>.doc ) {
329
<span class="comment">
330
      // Find feature by id</span>
331
      var feature = <span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"//wmc:ResourceList/*[@id='"</span>+layerId+<span class="literal">"']"</span>);
332
<span class="comment">
333
      // Fallback: find feature by name</span>
334
      <span class="reserved">if</span> (feature == null) {
335
        feature = <span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"//wmc:ResourceList/*[wmc:Name='"</span>+layerId+<span class="literal">"']"</span>);
336
      }
337

    
338
      <span class="reserved">if</span>(feature == null ) {
339
        alert(mbGetMessage(<span class="literal">"featureNotFoundOwsContext"</span>));
340
      }
341

    
342
      <span class="reserved">return</span> feature;
343
    }
344
  }
345

    
346
  <span class="comment">/**
347
   * Returns the serverUrl for the layer passed in as the feature argument.
348
   * <span class="attrib">@param</span> requestName ignored for context docs (only GetMap supported)
349
   * <span class="attrib">@param</span> method ignored for context docs (only GET supported)
350
   * <span class="attrib">@param</span> feature the node for the feature from the context doc
351
   * <span class="attrib">@return</span> height String URL for the GetMap request
352
   */</span>
353
  <span class="reserved">this</span>.getServerUrl = <span class="reserved">function</span>(requestName, method, feature) {
354
    var service = requestName.split(<span class="literal">":"</span>);
355
    <span class="reserved">if</span> (service.length &gt; 0) {
356
      service = service[0].toUpperCase();
357
    }
358
    var url = feature.selectSingleNode(<span class="literal">"wmc:Server[@service='OGC:"</span>+service+<span class="literal">"']/wmc:OnlineResource"</span>).getAttribute(<span class="literal">"xlink:href"</span>);
359
    <span class="reserved">if</span> (!url) {
360
<span class="comment">      // fallback to default service</span>
361
      url = feature.selectSingleNode(<span class="literal">"wmc:Server/wmc:OnlineResource"</span>).getAttribute(<span class="literal">"xlink:href"</span>);
362
    }
363
    <span class="reserved">return</span> url;
364
  }
365

    
366
  <span class="comment">/**
367
   * Returns the WMS version for the layer passed in as the feature argument
368
   * <span class="attrib">@param</span> feature the node for the feature from the context doc
369
   * <span class="attrib">@return</span> the WMS GetMap version for the Layer.
370
   */</span>
371
  <span class="reserved">this</span>.getVersion = <span class="reserved">function</span>(feature) {
372
    <span class="reserved">return</span> feature.selectSingleNode(<span class="literal">"wmc:Server"</span>).getAttribute(<span class="literal">"version"</span>);
373
  }
374

    
375
  <span class="comment">/**
376
   * Get HTTP method for the specified feature
377
   * <span class="attrib">@param</span> feature the Layer node from the context doc
378
   * <span class="attrib">@return</span> the HTTP method to get the feature with
379
   */</span>
380
  <span class="reserved">this</span>.getMethod = <span class="reserved">function</span>(feature) {
381
    <span class="reserved">return</span> feature.selectSingleNode(<span class="literal">"wmc:Server/wmc:OnlineResource"</span>).getAttribute(<span class="literal">"wmc:method"</span>);
382
  }
383

    
384
  <span class="comment">/**
385
   * Return the service type of the bottom layer in the layer list.
386
   * This is used to match navigation tools with the basemap.
387
   */</span>
388
  <span class="reserved">this</span>.getBaseLayerService=<span class="reserved">function</span>(){
389
<span class="comment">    //x=this.doc.selectSingleNode("/wmc:OWSContext/wmc:ResourceList/wmc:Layer[last()]/wmc:Server/<span class="attrib">@service</span>");</span>
390
    x=<span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:ResourceList/wmc:Layer[last()]/wmc:Server"</span>);
391
    s=x.getAttribute(<span class="literal">"service"</span>);
392
<span class="comment">    //alert("OwsContext.getBaseLayerService: s="+s);</span>
393
    <span class="reserved">return</span> s;
394
  }
395

    
396
  <span class="comment">/**
397
   * listener method which loads WFS features from the context doc, after WMS
398
   * layers are loaded.
399
   * <span class="attrib">@param</span> objRef Pointer to this object.
400
   */</span>
401
  <span class="reserved">this</span>.loadFeatures = <span class="reserved">function</span>(objRef) {
402
    var nodeSelectXpath = objRef.nodeSelectXpath + <span class="literal">"/wmc:FeatureType[wmc:Server/@service='OGC:WFS']/wmc:Name"</span>;
403
    var featureList = objRef.doc.selectNodes(nodeSelectXpath);
404
    <span class="reserved">for</span> (var i=0; i&lt;featureList.length; i++) {
405
      var featureName = getNodeValue(featureList[i]);
406
      objRef.setParam(<span class="literal">'wfs_GetFeature'</span>,featureName);
407
    }
408
<span class="comment">
409
    //this.callListeners("contextLoaded");  //PGC</span>
410
  }
411
  <span class="reserved">this</span>.addListener(<span class="literal">"loadModel"</span>, <span class="reserved">this</span>.loadFeatures, <span class="reserved">this</span>);
412

    
413
  <span class="comment">/**
414
   * Listener function which sets stylesheet params for WebServiceRequests
415
   * <span class="attrib">@param</span> objRef pointer to this object
416
   * <span class="attrib">@param</span> featureNodeId the id of the node in the doc to be processed by the stylesheet
417
   */</span>
418
  <span class="reserved">this</span>.setRequestParameters = <span class="reserved">function</span>(featureName, requestStylesheet) {
419
    var feature = <span class="reserved">this</span>.getFeatureNode(featureName);
420
    <span class="reserved">if</span> (feature.selectSingleNode(<span class="literal">"ogc:Filter"</span>)) {
421
      requestStylesheet.setParameter(<span class="literal">"filter"</span>, escape((new XMLSerializer()).serializeToString(feature.selectSingleNode(<span class="literal">"ogc:Filter"</span>))) );
422
    }
423
  }
424
<span class="comment">  //this.addFirstListener("wfs_GetFeature", this.setRequestParameters, this);</span>
425

    
426
  <span class="comment">/**
427
   * Method to get a list of queryable layers
428
   * <span class="attrib">@return</span> the list with queryable layers
429
   */</span>
430
  <span class="reserved">this</span>.getQueryableLayers = <span class="reserved">function</span>() {
431
    var listNodeArray = <span class="reserved">this</span>.doc.selectNodes(<span class="literal">"/wmc:OWSContext/wmc:ResourceList/wmc:Layer[@queryable='1']|/wmc:OWSContext/wmc:ResourceList/wmc:FeatureType[@queryable='1']"</span>);
432
    <span class="reserved">if</span> (listNodeArray == null) {
433
      listNodeArray = <span class="reserved">this</span>.doc.selectNodes(<span class="literal">"/wmc:OWSContext/wmc:ResourceList/wmc:Layer|/wmc:OWSContext/wmc:ResourceList/wmc:Layer"</span>);
434
    }
435
    <span class="reserved">return</span> listNodeArray;
436
  }
437

    
438
  <span class="comment">/**
439
   * Method to get a list of all layers in the context doc
440
   * TBD: merge this with above, passing queryable as an optional boolean param?
441
   * <span class="attrib">@TODO</span> Add the other layers
442
   * <span class="attrib">@return</span> the list with all layers
443
   */</span>
444
  <span class="reserved">this</span>.getAllLayers = <span class="reserved">function</span>() {
445
    var listNodeArray = <span class="reserved">this</span>.doc.selectNodes(<span class="literal">"//wmc:Layer|//wmc:FeatureType"</span>);
446
    <span class="reserved">return</span> listNodeArray;
447
  }
448

    
449
  <span class="comment">/**
450
   * Method to get a layer with the specified id/name in the context doc
451
   * <span class="attrib">@param</span> layerId/layerName the layer to be returned
452
   * <span class="attrib">@return</span> the list with all layers
453
   * <span class="attrib">@TODO</span> check other layers
454
   */</span>
455
  <span class="reserved">this</span>.getLayer = <span class="reserved">function</span>(layerId) {
456
    var layer = <span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:ResourceList/wmc:FeatureType[@id='"</span>+layerId+<span class="literal">"']"</span>);
457
    <span class="reserved">if</span> (layer == null) {
458
      layer = <span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:ResourceList/wmc:Layer[@id='"</span>+layerId+<span class="literal">"']"</span>);
459
    }
460
    <span class="reserved">if</span> (layer == null) {
461
      layer = <span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:ResourceList/wmc:Layer[wmc:Name='"</span>+layerId+<span class="literal">"']"</span>);
462
    }
463
    <span class="reserved">if</span> (layer == null) {
464
      layer = <span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:ResourceList/wmc:FeatureType[wmc:Name='"</span>+layerId+<span class="literal">"']"</span>);
465
    }
466
    <span class="reserved">if</span>( layer == null ) {
467
      layer = <span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:ResourceList/wmc:RssLayer[@id='"</span>+layerId+<span class="literal">"']"</span>);
468
    }
469
<span class="comment">    //TBD: add in time stamp</span>
470
    <span class="reserved">return</span> layer;
471
  }
472

    
473
  <span class="comment">/**
474
   * Method to get a layer id with the specified id/name in the context doc
475
   * <span class="attrib">@param</span> layerName the name of the layer of which the id is to be returned
476
   * <span class="attrib">@return</span> the id of the layer || false
477
   */</span>
478
  <span class="reserved">this</span>.getLayerIdByName = <span class="reserved">function</span>(layerName) {
479
    var layer = <span class="reserved">this</span>.getLayer(layerName);
480
    var id;
481
    <span class="reserved">if</span> (layer) {
482
      id = layer.getAttribute(<span class="literal">"id"</span>);
483
    }
484

    
485
    <span class="reserved">return</span> id || false;
486
  }
487

    
488

    
489
  <span class="comment">/**
490
   * Method to add a Layer to the LayerList
491
   * <span class="attrib">@param</span> layerNode the Layer node from another context doc or capabiltiies doc
492
   */</span>
493
  <span class="reserved">this</span>.addLayer = <span class="reserved">function</span>(objRef, layerNode) {
494
    <span class="reserved">if</span>( objRef.doc != null ) {
495
      var parentNode = objRef.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:ResourceList"</span>);
496
<span class="comment">
497
      // Generate layer id if layer doesn't have an id</span>
498
      var randomNumber = Math.round(10000 * Math.random());
499
      id = Mapbuilder.getProperty(layerNode, <span class="literal">"wmc:Name"</span>) + <span class="literal">"_"</span> + randomNumber; 
500
      layerNode.setAttribute(<span class="literal">"id"</span>, id);
501
<span class="comment">      
502
      // check if that node does not alreayd exist, replace it (query may have changed)</span>
503
      var id = layerNode.getAttribute(<span class="literal">"id"</span>);
504
      var str = <span class="literal">"/wmc:OWSContext/wmc:ResourceList/"</span>+layerNode.nodeName+<span class="literal">"[@id='"</span>+id+<span class="literal">"']"</span>;
505
      var node = objRef.doc.selectSingleNode(str);
506
      <span class="reserved">if</span>( node != null ) {
507
        parentNode.removeChild(node);
508
      }
509

    
510
      parentNode.appendChild(layerNode);
511
      objRef.modified = true;
512
      <span class="reserved">if</span> (<span class="reserved">this</span>.debug) {
513
         mbDebugMessage( <span class="literal">"Adding layer:"</span>+(new XMLSerializer()).serializeToString( layerNode ) );
514
      }
515
    } <span class="reserved">else</span> {
516
      alert(mbGetMessage(<span class="literal">"nullOwsContext"</span>));
517
    }
518
<span class="comment">    //objRef.callListeners("refresh");</span>
519
  }
520
  <span class="reserved">this</span>.addFirstListener( <span class="literal">"addLayer"</span>, <span class="reserved">this</span>.addLayer, <span class="reserved">this</span> );
521

    
522
  <span class="comment">/**
523
   * Method to get the baselayer 
524
   * <span class="attrib">@return</span> the baseLayer
525
   * <span class="attrib">@TODO</span> check for other baselayers
526
   */</span>
527
   <span class="reserved">this</span>.getBaseLayer = <span class="reserved">function</span>() {
528
      var baseLayer = <span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:ResourceList/ows:BaseLayer"</span>);
529
      <span class="reserved">return</span> baseLayer;
530
   }
531
   
532
 <span class="comment">/**
533
   * Method to add a Sld to the StyleList
534
   * <span class="attrib">@param</span> layerName the Layer name from another context doc or capabiltiies doc
535
   * TBD: make sure this will work again using layerId instead of layerName
536
   */</span>
537
  <span class="reserved">this</span>.addSLD = <span class="reserved">function</span>(objRef,sldNode) {
538
<span class="comment">    // alert("context addSLD : "+objRef.id);</span>
539
    var layerName=Mapbuilder.getProperty(sldNode, <span class="literal">"//Name"</span>);
540
    var parentNode = objRef.doc.selectSingleNode(<span class="literal">"//wmc:Layer[wmc:Name='"</span>+layerName+<span class="literal">"']"</span>);
541
    parentNode.appendChild(sldNode.cloneNode(true));
542

    
543
    objRef.modified = true;
544
      var attribs=[];
545
    attribs[<span class="literal">"sld_body"</span>]=(new XMLSerializer()).serializeToString(objRef.doc.selectSingleNode(<span class="literal">"//wmc:Layer[wmc:Name='"</span>+layerName+<span class="literal">"']/wmc:StyleList/wmc:Style/wmc:SLD/wmc:StyledLayerDescriptor"</span>));
546
    objRef.map.mbMapPane.refreshLayer(objRef.map.mbMapPane,layerName,attribs);
547
  }
548
  <span class="reserved">this</span>.addFirstListener( <span class="literal">"addSLD"</span>, <span class="reserved">this</span>.addSLD, <span class="reserved">this</span> );
549

    
550
  <span class="comment">/**
551
   * Method to remove a Layer from the LayerList
552
   * <span class="attrib">@param</span> layerId the Layer to be deleted
553
   */</span>
554
  <span class="reserved">this</span>.deleteLayer = <span class="reserved">function</span>(objRef, layerId) {
555
    var deletedNode = objRef.getLayer(layerId);
556
    <span class="reserved">if</span> (!deletedNode) {
557
      alert(mbGetMessage(<span class="literal">"nodeNotFound"</span>, layerId));
558
      <span class="reserved">return</span>;
559
    }
560
    deletedNode.parentNode.removeChild(deletedNode);
561
    objRef.modified = true;
562
  }
563
  <span class="reserved">this</span>.addFirstListener( <span class="literal">"deleteLayer"</span>, <span class="reserved">this</span>.deleteLayer, <span class="reserved">this</span> );
564

    
565
  <span class="comment">/**
566
   * Method to move a Layer in the LayerList up
567
   * <span class="attrib">@param</span> layerId the layer to be moved
568
   */</span>
569
  <span class="reserved">this</span>.moveLayerUp = <span class="reserved">function</span>(objRef, layerId) {
570
    var movedNode = objRef.getLayer(layerId);
571
    var sibNode = movedNode.selectSingleNode(<span class="literal">"following-sibling::*"</span>);
572
    <span class="reserved">if</span> (!sibNode) {
573
      alert(mbGetMessage(<span class="literal">"cantMoveUp"</span>, layerId));
574
      <span class="reserved">return</span>;
575
    }
576
    movedNode.parentNode.insertBefore(sibNode,movedNode);
577
    objRef.modified = true;
578
  }
579
  <span class="reserved">this</span>.addFirstListener( <span class="literal">"moveLayerUp"</span>, <span class="reserved">this</span>.moveLayerUp, <span class="reserved">this</span> );
580

    
581
  <span class="comment">/**
582
   * Method to move a Layer in the LayerList down
583
   * <span class="attrib">@param</span> layerId the layer to be moved
584
   */</span>
585
  <span class="reserved">this</span>.moveLayerDown = <span class="reserved">function</span>(objRef, layerId) {
586
    var movedNode = objRef.getLayer(layerId);
587
    var listNodeArray = movedNode.selectNodes(<span class="literal">"preceding-sibling::*"</span>);  //preceding-sibling axis contains all previous siblings
588
    var sibNode = listNodeArray[listNodeArray.length-1];
589
    <span class="reserved">if</span> (!sibNode) {
590
      alert(mbGetMessage(<span class="literal">"cantMoveDown"</span>, layerId));
591
      <span class="reserved">return</span>;
592
    }
593
    movedNode.parentNode.insertBefore(movedNode,sibNode);
594
    objRef.modified = true;
595
  }
596
  <span class="reserved">this</span>.addFirstListener( <span class="literal">"moveLayerDown"</span>, <span class="reserved">this</span>.moveLayerDown, <span class="reserved">this</span> );
597

    
598
  <span class="comment">/**
599
   * Adds a node to the Context document extension element.  The extension element
600
   * will be created if it doesn't already exist.
601
   * <span class="attrib">@param</span> extensionNode the node to be appended in the extension element.
602
   * <span class="attrib">@return</span> the ndoe added to the extension element
603
   */</span>
604
  <span class="reserved">this</span>.setExtension = <span class="reserved">function</span>(extensionNode) {
605
    var extension = <span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:General/wmc:Extension"</span>);
606
    <span class="reserved">if</span> (!extension) {
607
      var general = <span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:General"</span>);
608
      var newChild = createElementWithNS(<span class="reserved">this</span>.doc,<span class="literal">"Extension"</span>,<span class="literal">'http://www.opengis.net/context'</span>);
609
      extension = general.appendChild(newChild);
610
    }
611
    <span class="reserved">return</span> extension.appendChild(extensionNode);
612
  }
613

    
614
  <span class="comment">/**
615
   * Returns the contents of the extension element
616
   * <span class="attrib">@return</span> the contents of the extension element
617
   */</span>
618
  <span class="reserved">this</span>.getExtension = <span class="reserved">function</span>() {
619
    <span class="reserved">return</span> <span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:OWSContext/wmc:General/wmc:Extension"</span>);
620
  }
621
<span class="comment">
622
  // PL -BRGM</span>
623
  <span class="comment">/**
624
   * Change a Layer's opacity
625
   * <span class="attrib">@param</span> layerId  The name of the layer that is to be changed
626
   * <span class="attrib">@param</span> Opacity     Value of the opacity
627
   */</span>
628
  <span class="reserved">this</span>.setOpacity=<span class="reserved">function</span>(layerId, Opacity){
629
<span class="comment">    // Set the hidden attribute in the Context</span>
630
    var layer = <span class="reserved">this</span>.getLayer(layerId);
631
    <span class="reserved">if</span> (layer) layer.setAttribute(<span class="literal">"opacity"</span>, Opacity);
632
<span class="comment">    // Call the listeners</span>
633
    <span class="reserved">this</span>.callListeners(<span class="literal">"opacity"</span>, layerId);
634
  }
635

    
636
  <span class="comment">/**
637
   * Get the layer's opacity attribute value.
638
   * <span class="attrib">@param</span> layerId  The name of the layer that is to be changed
639
   * <span class="attrib">@return</span> hidden  String with the value; 1=hidden, 0=visible.
640
   */</span>
641
  <span class="reserved">this</span>.getOpacity=<span class="reserved">function</span>(layerId){
642
    var opacity=1;
643
    var layer = <span class="reserved">this</span>.getLayer(layerId);
644
    <span class="reserved">if</span> (layer) opacity = layer.getAttribute(<span class="literal">"opacity"</span>);
645
    <span class="reserved">return</span> opacity;
646
  }
647
<span class="comment">  // PL -END</span>
648
  
649
  <span class="comment">/**
650
   * Parses a Dimension element from the Context document as a loadModel listener.
651
   * This results in an XML structure with one element for each GetMap time value
652
   * parameter and added to the Context extrension element.
653
   * <span class="attrib">@param</span> objRef a pointer to this object
654
   */</span>
655
  <span class="reserved">this</span>.initTimeExtent = <span class="reserved">function</span>( objRef ) {
656
<span class="comment">    //only the first one selected is used as the timestamp source</span>
657
<span class="comment">    //var extentNode = objRef.doc.selectSingleNode("//wmc:Layer/wmc:Dimension[<span class="attrib">@name</span>='time']");</span>
658
<span class="comment">    //TBD: how to deal with multiple time dimensions in one context doc, or caps doc?</span>
659
    var timeNodes = objRef.doc.selectNodes(<span class="literal">"//wmc:Dimension[@name='time']"</span>);
660
    <span class="reserved">for</span> (var i=0; i&lt;timeNodes.length; ++i) {
661
      var extentNode = timeNodes[i];
662
      objRef.timestampList = createElementWithNS(objRef.doc,<span class="literal">"TimestampList"</span>,mbNsUrl);
663
      var layerId;
664
      var layerNode = extentNode.parentNode.parentNode;
665
      <span class="reserved">if</span> (layerNode.selectSingleNode(<span class="literal">"@id"</span>)) {
666
        layerId = Mapbuilder.getProperty(layerNode, <span class="literal">"@id"</span>);
667
      } <span class="reserved">else</span> {
668
        layerId =Mapbuilder.getProperty(layerNode, <span class="literal">"wmc:Name"</span>);
669
      }
670
      objRef.timestampList.setAttribute(<span class="literal">"layerId"</span>, layerId);
671
<span class="comment">      //alert("found time dimension, extent:"+getNodeValue(extentNode));</span>
672
      var times = getNodeValue(extentNode).split(<span class="literal">","</span>);   //comma separated list of arguments
673
      <span class="reserved">for</span> (var j=0; j&lt;times.length; ++j) {
674
        var params = times[j].split(<span class="literal">"/"</span>);     // parses start/end/period
675
        <span class="reserved">if</span> (params.length==3) {
676
          var start = setISODate(params[0]);
677
          var stop = setISODate(params[1]);
678
          var period = params[2];
679
          var parts = period.match(/^P((\d*)Y)?((\d*)M)?((\d*)D)?T?((\d*)H)?((\d*)M)?((.*)S)?/);
680
          <span class="reserved">for</span> (var i=1; i&lt;parts.length; ++i) {
681
            <span class="reserved">if</span> (!parts[i]) parts[i]=0;
682
          }
683
<span class="comment">          //alert("start time:"+start.toString());</span>
684
          do {
685
            var timestamp = createElementWithNS(objRef.doc,<span class="literal">"Timestamp"</span>,mbNsUrl);
686
            timestamp.appendChild(objRef.doc.createTextNode(getISODate(start)));
687
            objRef.timestampList.appendChild(timestamp);
688

    
689
            start.setFullYear(start.getFullYear()+parseInt(parts[2],10));
690
            start.setMonth(start.getMonth()+parseInt(parts[4],10));
691
            start.setDate(start.getDate()+parseInt(parts[6],10));
692
            start.setHours(start.getHours()+parseInt(parts[8],10));
693
            start.setMinutes(start.getMinutes()+parseInt(parts[10],10));
694
            start.setSeconds(start.getSeconds()+parseFloat(parts[12]));
695
<span class="comment">            //alert("time:"+start.toString());</span>
696
          } <span class="reserved">while</span>(start.getTime() &lt;= stop.getTime());
697

    
698
        } <span class="reserved">else</span> {
699
<span class="comment">          //output single date value</span>
700
          var timestamp = createElementWithNS(objRef.doc,<span class="literal">"Timestamp"</span>,mbNsUrl);
701
          timestamp.appendChild(objRef.doc.createTextNode(times[j]));
702
          objRef.timestampList.appendChild(timestamp);
703
        }
704
      }
705
     objRef.setExtension(objRef.timestampList);
706
    }
707
  }
708
  <span class="reserved">this</span>.addFirstListener( <span class="literal">"loadModel"</span>, <span class="reserved">this</span>.initTimeExtent, <span class="reserved">this</span> );
709

    
710
  <span class="comment">/**
711
   * clear the time extent created by initTimeExtent
712
   * <span class="attrib">@param</span> objRef reference to this model
713
   */</span>
714
  <span class="reserved">this</span>.clearTimeExtent = <span class="reserved">function</span>( objRef ) {
715
    var tsList = objRef.timestampList;
716
    <span class="reserved">if</span> (tsList) {
717
      tsList.parentNode.removeChild(tsList);
718
    }
719
  }
720
  <span class="reserved">this</span>.addListener(<span class="literal">"newModel"</span>, <span class="reserved">this</span>.clearTimeExtent, <span class="reserved">this</span>);
721

    
722
  <span class="comment">/**
723
   * Returns the current timestamp value.
724
   * <span class="attrib">@param</span> layerName the name of the Layer from which the timestamp list was generated
725
   * <span class="attrib">@return</span> the current timestamp value.
726
   */</span>
727
  <span class="reserved">this</span>.getCurrentTimestamp = <span class="reserved">function</span>( layerName ) {
728
    var index = <span class="reserved">this</span>.getParam(<span class="literal">"timestamp"</span>);
729
    <span class="reserved">return</span> getNodeValue(<span class="reserved">this</span>.timestampList.childNodes[index]);
730
  }
731

    
732
}
733
</pre>
734
	<hr>
735

    
736

    
737

    
738
<!-- ========== START OF NAVBAR ========== -->
739
<a name="navbar_top"><!-- --></a>
740
<table border="0" width="100%" cellpadding="1" cellspacing="0">
741
<tr>
742
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
743
<a name="navbar_top_firstrow"><!-- --></a>
744
<table border="0" cellpadding="0" cellspacing="3">
745
  <tr align="center" valign="top">
746
  
747
  
748
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
749
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
750
  
751

    
752
  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
753
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
754
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
755
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
756
  </tr>
757
</table>
758
</td>
759
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
760
<b><a href='http://mapbuilder.sourceforge.net'>Community Map Builder</a> 27 Apr 2008</b></em>
761
</td>
762
</tr>
763

    
764
<tr>
765
<td bgcolor="white" class="NavBarCell2"><font size="-2">
766
&nbsp;PREV&nbsp;
767
&nbsp;NEXT</font></td>
768
<td bgcolor="white" class="NavBarCell2"><font size="-2">
769
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
770
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
771
&nbsp;&nbsp;
772
<script>
773
  <!--
774
  if(window==top) {
775
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
776
  }
777
  //-->
778
</script>
779
<noscript>
780
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
781
</noscript>
782
</font></td>
783
</tr>
784
</table>
785
<!-- =========== END OF NAVBAR =========== -->
786

    
787
<hr>
788
<font size="-1">
789

    
790
</font>
791
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Sun Apr 27 20:30:54 2008</div>
792
</body>
793
</html>
(276-276/316)