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="Context.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>Context.js</h2>
72
	
73
</center>
74

    
75
	
76

    
77

    
78
<h4>Summary</h4>
79
<p>
80
	
81
		No overview generated for 'Context.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="Context.html">Context</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: Context.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 a Web Map Context (WMC) document as defined by the Open Geospatial Consortium
121
 * (http://www.opengeospatial.org/) and extensions the the WMC.
122
 *
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
 *
127
 * <span class="attrib">@constructor</span>
128
 * <span class="attrib">@base</span> ModelBase
129
 * <span class="attrib">@author</span> Cameron Shorter
130
 * <span class="attrib">@param</span> modelNode Pointer to the xml node for this model from the config file.
131
 * <span class="attrib">@param</span> parent    The parent model for the object.
132
  *
133
 */</span>
134
<span class="reserved">function</span> Context(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

    
138
  <span class="reserved">this</span>.namespace = <span class="literal">"xmlns:mb='http://mapbuilder.sourceforge.net/mapbuilder' xmlns:wmc='http://www.opengis.net/context' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'"</span>;
139

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

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

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

    
168
  <span class="comment">/**
169
   * Get the BoundingBox value from the Context document.
170
   * <span class="attrib">@return</span> BoundingBox array with the sequence (xmin,ymin,xmax,ymax).
171
   */</span>
172
  <span class="reserved">this</span>.getBoundingBox=<span class="reserved">function</span>() {
173
    var bbox = new Array();
174
<span class="comment">    // Extract BoundingBox from the context</span>
175
    var boundingBox=<span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:ViewContext/wmc:General/wmc:BoundingBox"</span>);
176
    bbox[0]=parseFloat(boundingBox.getAttribute(<span class="literal">"minx"</span>));
177
    bbox[1]=parseFloat(boundingBox.getAttribute(<span class="literal">"miny"</span>));
178
    bbox[2]=parseFloat(boundingBox.getAttribute(<span class="literal">"maxx"</span>));
179
    bbox[3]=parseFloat(boundingBox.getAttribute(<span class="literal">"maxy"</span>));
180
    <span class="reserved">return</span> bbox;
181
  }
182

    
183
  <span class="comment">/**
184
   * Set the BoundingBox element and call the refresh listeners
185
   * <span class="attrib">@param</span> boundingBox array in the sequence (xmin, ymin, xmax, ymax).
186
   */</span>
187
  <span class="reserved">this</span>.setBoundingBox=<span class="reserved">function</span>(boundingBox) {
188
<span class="comment">    // Set BoundingBox in context</span>
189
    var bbox=<span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:ViewContext/wmc:General/wmc:BoundingBox"</span>);
190
    bbox.setAttribute(<span class="literal">"minx"</span>, boundingBox[0]);
191
    bbox.setAttribute(<span class="literal">"miny"</span>, boundingBox[1]);
192
    bbox.setAttribute(<span class="literal">"maxx"</span>, boundingBox[2]);
193
    bbox.setAttribute(<span class="literal">"maxy"</span>, boundingBox[3]);
194
<span class="comment">    // Call the listeners</span>
195
    <span class="reserved">this</span>.callListeners(<span class="literal">"bbox"</span>, boundingBox);
196
  }
197

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

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

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

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

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

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

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

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

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

    
294
  <span class="comment">/**
295
   * Returns the width/height of the map window as an array
296
   */</span>
297
  <span class="reserved">this</span>.getWindowSize=<span class="reserved">function</span>() {
298
    var win=<span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:ViewContext/wmc:General/wmc:Window"</span>);
299
    <span class="reserved">return</span> new Array(win.getAttribute(<span class="literal">"width"</span>), win.getAttribute(<span class="literal">"height"</span>));
300
  }
301

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

    
318
  <span class="comment">/**
319
   * Returns the Layer node with the specified name from the list of nodes
320
   * selected by the nodeSelectXpath from the capabilities doc.
321
   * <span class="attrib">@param</span> featureName name of the featureType to look up
322
   * <span class="attrib">@return</span> the Layer node with the specified name.
323
   */</span>
324
  <span class="reserved">this</span>.getFeatureNode = <span class="reserved">function</span>(featureName) {
325
    <span class="reserved">return</span> <span class="reserved">this</span>.doc.selectSingleNode(<span class="reserved">this</span>.nodeSelectXpath+<span class="literal">"[wmc:Name='"</span>+featureName+<span class="literal">"']"</span>);
326
  }
327

    
328
  <span class="comment">/**
329
   * Returns the serverUrl for the layer passed in as the feature argument.
330
   * <span class="attrib">@param</span> requestName ignored for context docs (only GetMap supported)
331
   * <span class="attrib">@param</span> method ignored for context docs (only GET supported)
332
   * <span class="attrib">@param</span> feature the Layer node from the context doc
333
   * <span class="attrib">@return</span> URL for the GetMap request
334
   */</span>
335
  <span class="reserved">this</span>.getServerUrl = <span class="reserved">function</span>(requestName, method, feature) {
336
    <span class="reserved">return</span> feature.selectSingleNode(<span class="literal">"wmc:Server/wmc:OnlineResource"</span>).getAttribute(<span class="literal">"xlink:href"</span>);
337
  }
338

    
339
  <span class="comment">/**
340
   * Returns the WMS version for the layer passed in as the feature argument
341
   * <span class="attrib">@param</span> feature the Layer node from the context doc
342
   * <span class="attrib">@return</span> the WMS GetMap version for the Layer.
343
   */</span>
344
  <span class="reserved">this</span>.getVersion = <span class="reserved">function</span>(feature) {
345
    <span class="reserved">return</span> feature.selectSingleNode(<span class="literal">"wmc:Server"</span>).getAttribute(<span class="literal">"version"</span>);
346
  }
347

    
348
  <span class="comment">/**
349
   * Get HTTP method for the specified feature
350
   * <span class="attrib">@param</span> feature the Layer node from the context doc
351
   * <span class="attrib">@return</span> the HTTP method to get the feature with
352
   */</span>
353
  <span class="reserved">this</span>.getMethod = <span class="reserved">function</span>(feature) {
354
    <span class="reserved">return</span> feature.selectSingleNode(<span class="literal">"wmc:Server/wmc:OnlineResource"</span>).getAttribute(<span class="literal">"wmc:method"</span>);
355
  }
356

    
357
  <span class="comment">/**
358
   * Method to get a list of queryable layers
359
   * <span class="attrib">@return</span> the list with queryable layers
360
   */</span>
361
  <span class="reserved">this</span>.getQueryableLayers = <span class="reserved">function</span>() {
362
    var listNodeArray = <span class="reserved">this</span>.doc.selectNodes(<span class="literal">"/wmc:ViewContext/wmc:LayerList/wmc:Layer[attribute::queryable='1']"</span>);
363
    <span class="reserved">return</span> listNodeArray;
364
  }
365

    
366
  <span class="comment">/**
367
   * Method to get a list of all layers in the context doc
368
   * TBD: merge this with above, passing queryable as an optional boolean param?
369
   * <span class="attrib">@return</span> the list with all layers
370
   */</span>
371
  <span class="reserved">this</span>.getAllLayers = <span class="reserved">function</span>() {
372
    var listNodeArray = <span class="reserved">this</span>.doc.selectNodes(<span class="literal">"/wmc:ViewContext/wmc:LayerList/wmc:Layer"</span>);
373
    <span class="reserved">return</span> listNodeArray;
374
  }
375

    
376
  <span class="comment">/**
377
   * Method to get a layer with the specified name in the context doc
378
   * <span class="attrib">@param</span> layerId the id of the layer to be returned
379
   * <span class="attrib">@return</span> the list with all layers
380
   */</span>
381
  <span class="reserved">this</span>.getLayer = <span class="reserved">function</span>(layerId) {
382
    var layer = <span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:ViewContext/wmc:LayerList/wmc:Layer[@id='"</span>+layerId+<span class="literal">"']"</span>);
383
    <span class="reserved">if</span> (layer == null) {
384
      layer = <span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:ViewContext/wmc:LayerList/wmc:Layer[wmc:Name='"</span>+layerId+<span class="literal">"']"</span>);
385
    }
386
<span class="comment">    //TBD: add in time stamp</span>
387
    <span class="reserved">return</span> layer;
388
  }
389

    
390
  <span class="comment">/**
391
   * Method to get a layer id with the specified id/name in the context doc
392
   * <span class="attrib">@param</span> layerName the name of the layer of which the id is to be returned
393
   * <span class="attrib">@return</span> the id of the layer || false
394
   */</span>
395
  <span class="reserved">this</span>.getLayerIdByName = <span class="reserved">function</span>(layerName) {
396
    var layer = <span class="reserved">this</span>.getLayer(layerName);
397
    var id;
398
    <span class="reserved">if</span> (layer) {
399
      id = layer.getAttribute(<span class="literal">"id"</span>);
400
    }
401

    
402
    <span class="reserved">return</span> id || false;
403
  }
404

    
405
  <span class="comment">/**
406
   * Method to add a Layer to the LayerList
407
   * <span class="attrib">@param</span> layerNode the Layer node from another context doc or capabiltiies doc
408
   */</span>
409
  <span class="reserved">this</span>.addLayer = <span class="reserved">function</span>(objRef, layerNode) {
410

    
411
    var parentNode = objRef.doc.selectSingleNode(<span class="literal">"/wmc:ViewContext/wmc:LayerList"</span>);
412
    parentNode.appendChild(layerNode);
413
<span class="comment">
414
    // Generate layer id if layer doesn't have an id</span>
415
    <span class="reserved">if</span> (!layerNode.getAttribute(<span class="literal">"id"</span>)) {
416
      var randomNumber = Math.round(10000 * Math.random());
417
      id = Mapbuilder.getProperty(layerNode, <span class="literal">"wmc:Name"</span>) + <span class="literal">"_"</span> + randomNumber; 
418
      layerNode.setAttribute(<span class="literal">"id"</span>, id);
419
    }
420

    
421
    objRef.modified = true;
422
<span class="comment">    //objRef.callListeners("refresh");</span>
423
  }
424
  <span class="reserved">this</span>.addFirstListener( <span class="literal">"addLayer"</span>, <span class="reserved">this</span>.addLayer, <span class="reserved">this</span> );
425

    
426
 <span class="comment">/**
427
   * Method to add a Sld tag to the StyleList
428
   * <span class="attrib">@param</span> layerName the Layer name from another context doc or capabiltiies doc
429
   */</span>
430
  <span class="reserved">this</span>.addSLD = <span class="reserved">function</span>(objRef,sldNode) {
431
<span class="comment">    // alert("context addSLD : "+objRef.id);</span>
432
    var layerName=Mapbuilder.getProperty(sldNode, <span class="literal">"//Name"</span>);
433
    var parentNode = objRef.doc.selectSingleNode(<span class="literal">"//wmc:Layer[wmc:Name='"</span>+layerName+<span class="literal">"']"</span>);
434
    parentNode.appendChild(sldNode.cloneNode(true));
435
    objRef.modified = true;
436
    var attribs=[];
437
    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>));
438
	objRef.map.mbMapPane.refreshLayer(objRef.map.mbMapPane,layerName,attribs);
439
	
440
  }
441
  <span class="reserved">this</span>.addFirstListener( <span class="literal">"addSLD"</span>, <span class="reserved">this</span>.addSLD, <span class="reserved">this</span> );
442

    
443
  <span class="comment">/**
444
   * Method to remove a Layer from the LayerList
445
   * <span class="attrib">@param</span> layerId the Layer to be deleted
446
   */</span>
447
  <span class="reserved">this</span>.deleteLayer = <span class="reserved">function</span>(objRef, layerId) {
448
    var deletedNode = objRef.getLayer(layerId);
449
    <span class="reserved">if</span> (!deletedNode) {
450
      alert(mbGetMessage(<span class="literal">"nodeNotFound"</span>, layerId));
451
      <span class="reserved">return</span>;
452
    }
453
    deletedNode.parentNode.removeChild(deletedNode);
454
    objRef.modified = true;
455
  }
456
  <span class="reserved">this</span>.addFirstListener( <span class="literal">"deleteLayer"</span>, <span class="reserved">this</span>.deleteLayer, <span class="reserved">this</span> );
457

    
458
  <span class="comment">/**
459
   * Method to move a Layer in the LayerList up
460
   * <span class="attrib">@param</span> layerId the layer to be moved
461
   */</span>
462
  <span class="reserved">this</span>.moveLayerUp = <span class="reserved">function</span>(objRef, layerId) {
463
    var movedNode = objRef.getLayer(layerId);
464
    var sibNode = movedNode.selectSingleNode(<span class="literal">"following-sibling::*"</span>);
465
    <span class="reserved">if</span> (!sibNode) {
466
      alert(mbGetMessage(<span class="literal">"cantMoveUp"</span>, layerId));
467
      <span class="reserved">return</span>;
468
    }
469
    movedNode.parentNode.insertBefore(sibNode,movedNode);
470
    objRef.modified = true;
471
  }
472
  <span class="reserved">this</span>.addFirstListener( <span class="literal">"moveLayerUp"</span>, <span class="reserved">this</span>.moveLayerUp, <span class="reserved">this</span> );
473

    
474
  <span class="comment">/**
475
   * Method to move a Layer in the LayerList down
476
   * <span class="attrib">@param</span> layerId the layer to be moved
477
   */</span>
478
  <span class="reserved">this</span>.moveLayerDown = <span class="reserved">function</span>(objRef, layerId) {
479
    var movedNode = objRef.getLayer(layerId);
480
    var listNodeArray = movedNode.selectNodes(<span class="literal">"preceding-sibling::*"</span>);  //preceding-sibling axis contains all previous siblings
481
    var sibNode = listNodeArray[listNodeArray.length-1];
482
    <span class="reserved">if</span> (!sibNode) {
483
      alert(mbGetMessage(<span class="literal">"cantMoveDown"</span>, layerId));
484
      <span class="reserved">return</span>;
485
    }
486
    movedNode.parentNode.insertBefore(movedNode,sibNode);
487
    objRef.modified = true;
488
  }
489
  <span class="reserved">this</span>.addFirstListener( <span class="literal">"moveLayerDown"</span>, <span class="reserved">this</span>.moveLayerDown, <span class="reserved">this</span> );
490

    
491
  <span class="comment">/**
492
   * Adds a node to the Context document extension element.  The extension element
493
   * will be created if it doesn't already exist.
494
   * <span class="attrib">@param</span> extensionNode the node to be appended in the extension element.
495
   * <span class="attrib">@return</span> the ndoe added to the extension element
496
   */</span>
497
  <span class="reserved">this</span>.setExtension = <span class="reserved">function</span>(extensionNode) {
498
    var extension = <span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:ViewContext/wmc:General/wmc:Extension"</span>);
499
    <span class="reserved">if</span> (!extension) {
500
      var general = <span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:ViewContext/wmc:General"</span>);
501
      var newChild = createElementWithNS(<span class="reserved">this</span>.doc,<span class="literal">"Extension"</span>,<span class="literal">'http://www.opengis.net/context'</span>);
502
      extension = general.appendChild(newChild);
503
    }
504
    <span class="reserved">return</span> extension.appendChild(extensionNode);
505
  }
506

    
507
  <span class="comment">/**
508
   * Returns the contents of the extension element
509
   * <span class="attrib">@return</span> the contents of the extension element
510
   */</span>
511
  <span class="reserved">this</span>.getExtension = <span class="reserved">function</span>() {
512
    <span class="reserved">return</span> <span class="reserved">this</span>.doc.selectSingleNode(<span class="literal">"/wmc:ViewContext/wmc:General/wmc:Extension"</span>);
513
  }
514

    
515
  <span class="comment">/**
516
   * Parses a Dimension element from the Context document as a loadModel listener.
517
   * This results in an XML structure with one element for each GetMap time value
518
   * parameter and added to the Context extrension element.
519
   * <span class="attrib">@param</span> objRef a pointer to this object
520
   */</span>
521
  <span class="reserved">this</span>.initTimeExtent = <span class="reserved">function</span>( objRef ) {
522
<span class="comment">    //only the first one selected is used as the timestamp source</span>
523
<span class="comment">    //var extentNode = objRef.doc.selectSingleNode("//wmc:Layer/wmc:Dimension[<span class="attrib">@name</span>='time']");</span>
524
<span class="comment">    //TBD: how to deal with multiple time dimensions in one context doc, or caps doc?</span>
525
    var timeNodes = objRef.doc.selectNodes(<span class="literal">"//wmc:Dimension[@name='time']"</span>);
526
    <span class="reserved">for</span> (var i=0; i&lt;timeNodes.length; ++i) {
527
      var extentNode = timeNodes[i];
528
      objRef.timestampList = createElementWithNS(objRef.doc,<span class="literal">"TimestampList"</span>,mbNsUrl);
529
      var layerId;
530
      var layerNode = extentNode.parentNode.parentNode;
531
      <span class="reserved">if</span> (layerNode.selectSingleNode(<span class="literal">"@id"</span>)) {
532
        layerId = Mapbuilder.getProperty(layerNode, <span class="literal">"@id"</span>);
533
      } <span class="reserved">else</span> {
534
        layerId = Mapbuilder.getProperty(layerNode, <span class="literal">"wmc:Name"</span>);
535
      }
536
      objRef.timestampList.setAttribute(<span class="literal">"layerId"</span>, layerId);
537
<span class="comment">      //alert("found time dimension, extent:"+getNodeValue(extentNode));</span>
538
      var times = getNodeValue(extentNode).split(<span class="literal">","</span>);   //comma separated list of arguments
539
      <span class="reserved">for</span> (var j=0; j&lt;times.length; ++j) {
540
        var params = times[j].split(<span class="literal">"/"</span>);     // parses start/end/period
541
        <span class="reserved">if</span> (params.length==3) {
542
          var start = setISODate(params[0]);
543
          var stop = setISODate(params[1]);
544
          var period = params[2];
545
          var parts = period.match(/^P((\d*)Y)?((\d*)M)?((\d*)D)?T?((\d*)H)?((\d*)M)?((.*)S)?/);
546
          <span class="reserved">for</span> (var i=1; i&lt;parts.length; ++i) {
547
            <span class="reserved">if</span> (!parts[i]) parts[i]=0;
548
          }
549
<span class="comment">          //alert("start time:"+start.toString());</span>
550
          do {
551
            var timestamp = createElementWithNS(objRef.doc,<span class="literal">"Timestamp"</span>,mbNsUrl);
552
            timestamp.appendChild(objRef.doc.createTextNode(getISODate(start)));
553
            objRef.timestampList.appendChild(timestamp);
554

    
555
            start.setFullYear(start.getFullYear()+parseInt(parts[2],10));
556
            start.setMonth(start.getMonth()+parseInt(parts[4],10));
557
            start.setDate(start.getDate()+parseInt(parts[6],10));
558
            start.setHours(start.getHours()+parseInt(parts[8],10));
559
            start.setMinutes(start.getMinutes()+parseInt(parts[10],10));
560
            start.setSeconds(start.getSeconds()+parseFloat(parts[12]));
561
<span class="comment">            //alert("time:"+start.toString());</span>
562
          } <span class="reserved">while</span>(start.getTime() &lt;= stop.getTime());
563

    
564
        } <span class="reserved">else</span> {
565
<span class="comment">          //output single date value</span>
566
          var timestamp = createElementWithNS(objRef.doc,<span class="literal">"Timestamp"</span>,mbNsUrl);
567
          timestamp.appendChild(objRef.doc.createTextNode(times[j]));
568
          objRef.timestampList.appendChild(timestamp);
569
        }
570
      }
571
     objRef.setExtension(objRef.timestampList);
572
    }
573
  }
574
  <span class="reserved">this</span>.addFirstListener( <span class="literal">"loadModel"</span>, <span class="reserved">this</span>.initTimeExtent, <span class="reserved">this</span> );
575
  
576
  <span class="comment">/**
577
   * clear the time extent created by initTimeExtent
578
   * <span class="attrib">@param</span> objRef reference to this model
579
   */</span>
580
  <span class="reserved">this</span>.clearTimeExtent = <span class="reserved">function</span>( objRef ) {
581
    var tsList = objRef.timestampList;
582
    <span class="reserved">if</span> (tsList) {
583
      tsList.parentNode.removeChild(tsList);
584
    }
585
  }
586
  <span class="reserved">this</span>.addListener(<span class="literal">"newModel"</span>, <span class="reserved">this</span>.clearTimeExtent, <span class="reserved">this</span>);
587

    
588
  <span class="comment">/**
589
   * Returns the current timestamp value.
590
   * <span class="attrib">@param</span> layerId the name of the Layer from which the timestamp list was generated
591
   * <span class="attrib">@return</span> the current timestamp value.
592
   */</span>
593
  <span class="reserved">this</span>.getCurrentTimestamp = <span class="reserved">function</span>( layerId ) {
594
    var index = <span class="reserved">this</span>.getParam(<span class="literal">"timestamp"</span>);
595
    <span class="reserved">return</span> getNodeValue(<span class="reserved">this</span>.timestampList.childNodes[index]);
596
  }
597
<span class="comment">
598
  // PL -BRGM</span>
599
  <span class="comment">/**
600
   * Change a Layer's opacity
601
   * <span class="attrib">@param</span> layerId  The name of the layer that is to be changed
602
   * <span class="attrib">@param</span> Opacity     Value of the opacity
603
   */</span>
604
  <span class="reserved">this</span>.setOpacity=<span class="reserved">function</span>(layerId, Opacity){
605
<span class="comment">    // Set the hidden attribute in the Context</span>
606
    var layer = <span class="reserved">this</span>.getLayer(layerId);
607
    <span class="reserved">if</span> (layer) layer.setAttribute(<span class="literal">"opacity"</span>, Opacity);
608
<span class="comment">    // Call the listeners</span>
609
    <span class="reserved">this</span>.callListeners(<span class="literal">"opacity"</span>, layerId);
610
  }
611

    
612
  <span class="comment">/**
613
   * Get the layer's opacity attribute value.
614
   * <span class="attrib">@param</span> layerId  The name of the layer that is to be changed
615
   * <span class="attrib">@return</span> hidden  String with the value; 1=hidden, 0=visible.
616
   */</span>
617
  <span class="reserved">this</span>.getOpacity=<span class="reserved">function</span>(layerId){
618
    var opacity=1;
619
    var layer = <span class="reserved">this</span>.getLayer(layerId);
620
    <span class="reserved">if</span> (layer) opacity = layer.getAttribute(<span class="literal">"opacity"</span>);
621
    <span class="reserved">return</span> opacity;
622
  }
623
<span class="comment">  // PL -END</span>
624
}
625
</pre>
626
	<hr>
627

    
628

    
629

    
630
<!-- ========== START OF NAVBAR ========== -->
631
<a name="navbar_top"><!-- --></a>
632
<table border="0" width="100%" cellpadding="1" cellspacing="0">
633
<tr>
634
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
635
<a name="navbar_top_firstrow"><!-- --></a>
636
<table border="0" cellpadding="0" cellspacing="3">
637
  <tr align="center" valign="top">
638
  
639
  
640
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
641
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
642
  
643

    
644
  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
645
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
646
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
647
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
648
  </tr>
649
</table>
650
</td>
651
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
652
<b><a href='http://mapbuilder.sourceforge.net'>Community Map Builder</a> 27 Apr 2008</b></em>
653
</td>
654
</tr>
655

    
656
<tr>
657
<td bgcolor="white" class="NavBarCell2"><font size="-2">
658
&nbsp;PREV&nbsp;
659
&nbsp;NEXT</font></td>
660
<td bgcolor="white" class="NavBarCell2"><font size="-2">
661
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
662
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
663
&nbsp;&nbsp;
664
<script>
665
  <!--
666
  if(window==top) {
667
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
668
  }
669
  //-->
670
</script>
671
<noscript>
672
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
673
</noscript>
674
</font></td>
675
</tr>
676
</table>
677
<!-- =========== END OF NAVBAR =========== -->
678

    
679
<hr>
680
<font size="-1">
681

    
682
</font>
683
<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>
684
</body>
685
</html>
(224-224/316)