Project

General

Profile

1
/*
2
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
3
$Id$
4
*/
5

    
6
/**
7
 * Stores an OWS Context document as defined by the OGC interoperability
8
 * experiment. This model should be eventually merged with the standard OGC 
9
 * context doc.
10
 * Listeners supported by this model:
11
 * "refresh" called when window parameters (width/height, bbox) are changed
12
 * "hidden" called when visibilty of a layer is changed
13
 * "wfs_getFeature" called when feature resources are loaded
14
 *
15
 * @constructor
16
 * @base ModelBase
17
 * @author Mike Adair
18
 * @requires Sarissa
19
 * 
20
 */
21
function OwsContext(modelNode, parent) {
22
  // Inherit the ModelBase functions and parameters
23
  ModelBase.apply(this, new Array(modelNode, parent));
24

    
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'";
26

    
27
  // ===============================
28
  // Update of Context Parameters
29
  // ===============================
30

    
31
  /**
32
   * Change a Layer's visibility.
33
   * @param layerName  The name of the layer that is to be changed
34
   * @param hidden     String with the value to be set; 1=hidden, 0=visible.
35
   */
36
  this.setHidden=function(layerName, hidden){
37
    // Set the hidden attribute in the Context
38
    var hiddenValue = "0";
39
    if (hidden) hiddenValue = "1";
40
      
41
    var layer=this.getFeatureNode(layerName);
42
    layer.setAttribute("hidden", hiddenValue);
43
    // Call the listeners
44
    this.callListeners("hidden", layerName);
45
  }
46

    
47
  /**
48
   * Get the layer's visiblity attribute value.
49
   * @param layerName  The name of the layer that is to be changed
50
   * @return hidden  String with the value; 1=hidden, 0=visible.
51
   */
52
  this.getHidden=function(layerName){
53
    var hidden=1;
54
    var layer=this.getFeatureNode(layerName)
55
    return layer.getAttribute("hidden");
56
  }
57

    
58
  /**
59
   * Get the BoundingBox.
60
   * @return BoundingBox array in form (xmin,ymin,xmax,ymax).
61
   */
62
  this.getBoundingBox=function() {
63
    // Extract BoundingBox from the context
64
    //boundingBox=this.doc.documentElement.getElementsByTagName("BoundingBox").item(0);
65
    var lowerLeft=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/ows:BoundingBox/ows:LowerCorner");
66
    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
    for (i=0; i<strBbox.length; ++i) {
70
      bbox[i] = parseFloat(strBbox[i]);
71
    }
72
    return bbox;
73
  }
74

    
75
  /**
76
   * Set the BoundingBox element and call the refresh listeners
77
   * @param boundingBox array in the sequence (xmin, ymin, xmax, ymax).
78
   */
79
  this.setBoundingBox=function(boundingBox) {
80
    // Set BoundingBox in context
81
    var lowerLeft=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/ows:BoundingBox/ows:LowerCorner");
82
    lowerLeft.firstChild.nodeValue = boundingBox[0] + " " + boundingBox[1];
83
    var upperRight=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/ows:BoundingBox/ows:UpperCorner");
84
    upperRight.firstChild.nodeValue = boundingBox[2] + " " + boundingBox[3];
85
    // Call the listeners
86
    this.callListeners("bbox");
87
  }
88

    
89
  /**
90
   * Set the Spacial Reference System for layer display and layer requests.
91
   * @param srs The Spatial Reference System.
92
   */
93
  this.setSRS=function(srs) {
94
    //bbox=this.doc.documentElement.getElementsByTagName("BoundingBox").item(0);
95
    var bbox=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/ows:BoundingBox");
96
    bbox.setAttribute("crs",srs);
97
    this.callListeners("srs");
98
  }
99

    
100
  /**
101
   * Set the Spacial Reference System for layer display and layer requests.
102
   * @return srs The Spatial Reference System.
103
   */
104
  this.getSRS=function() {
105
    //bbox=this.doc.documentElement.getElementsByTagName("BoundingBox").item(0);
106
    var bbox=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/ows:BoundingBox");
107
    srs=bbox.getAttribute("crs");
108
    return srs;
109
  }
110

    
111
  /**
112
   * Get the Window width.
113
   * @return width The width of map window from the context document
114
   */
115
  this.getWindowWidth=function() {
116
    //var win=this.doc.documentElement.getElementsByTagName("Window").item(0);
117
    var win=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/wmc:Window");
118
    width=win.getAttribute("width");
119
    return width;
120
  }
121

    
122
  /**
123
   * Set the Window width.
124
   * @param width The width of map window (therefore of map layer images).
125
   */
126
  this.setWindowWidth=function(width) {
127
    //win=this.doc.documentElement.getElementsByTagName("Window").item(0);
128
    var win=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/wmc:Window");
129
    win.setAttribute("width", width);
130
    this.callListeners("resize");
131
  }
132

    
133
  /**
134
   * Get the Window height.
135
   * @return height The height of map window from the context document.
136
   */
137
  this.getWindowHeight=function() {
138
    //var win=this.doc.documentElement.getElementsByTagName("Window").item(0);
139
    var win=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/wmc:Window");
140
    height=win.getAttribute("height");
141
    return height;
142
  }
143

    
144
  /**
145
   * Set the Window height.
146
   * @param height The height of map window (therefore of map layer images).
147
   */
148
  this.setWindowHeight=function(height) {
149
    //win=this.doc.documentElement.getElementsByTagName("Window").item(0);
150
    var win=this.doc.selectSingleNode("/wmc:OWSContext/wmc:General/wmc:Window");
151
    win.setAttribute("height", height);
152
    this.callListeners("resize");
153
  }
154

    
155
  /**
156
   * Returns the serverUrl for the layer passed in as the feature argument.
157
   * @param requestName ignored for context docs (only GetMap supported)
158
   * @param method ignored for context docs (only GET supported)
159
   * @param feature the node for the feature from the context doc
160
   * @return height String URL for the GetMap request
161
   */
162
  this.getServerUrl = function(requestName, method, feature) {
163
    return feature.selectSingleNode("wmc:Server/wmc:OnlineResource").getAttribute("xlink:href");
164
  }
165

    
166
  /**
167
   * Returns the WMS version for the layer passed in as the feature argument
168
   * @param feature the node for the feature from the context doc
169
   * @return the WMS GetMap version for the Layer.
170
   */
171
  this.getVersion = function(feature) {  
172
    return feature.selectSingleNode("wmc:Server").getAttribute("version");
173
  }
174

    
175
  /**
176
   * Get HTTP method for the specified feature
177
   * @param feature the Layer node from the context doc
178
   * @return the HTTP method to get the feature with
179
   */
180
  this.getMethod = function(feature) {
181
    return feature.selectSingleNode("wmc:Server/wmc:OnlineResource").getAttribute("wmc:method");
182
  }
183

    
184
  /**
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
188
   */
189
  this.getFeatureNode = function(featureName) {
190
    return this.doc.selectSingleNode(this.nodeSelectXpath+"/*[wmc:Name='"+featureName+"']");
191
  }
192

    
193
  /**
194
   * listener method which loads WFS features from the context doc, after WMS 
195
   * layers are loaded.
196
   * @param objRef Pointer to this object.
197
   */
198
  this.loadFeatures = function(objRef) {
199
    var nodeSelectXpath = objRef.nodeSelectXpath + "/wmc:FeatureType[wmc:Server/@service='OGC:WFS']/wmc:Name";
200
    var featureList = objRef.doc.selectNodes(nodeSelectXpath);
201
    for (var i=0; i<featureList.length; i++) {
202
      var featureName = featureList[i].firstChild.nodeValue;
203
      objRef.setParam('wfs_GetFeature',featureName);
204
    }
205
  }
206
  this.addListener("loadModel", this.loadFeatures, this);
207

    
208
  /**
209
   * Listener function which sets stylesheet params for WebServiceRequests
210
   * @param objRef pointer to this object
211
   * @param featureNodeId the id of the node in the doc to be processed by the stylesheet
212
   */
213
  this.setRequestParameters = function(featureName, requestStylesheet) {
214
    var feature = this.getFeatureNode(featureName);
215
    if (feature.selectSingleNode("ogc:Filter")) {
216
      requestStylesheet.setParameter("filter", escape(Sarissa.serialize(feature.selectSingleNode("ogc:Filter"))) );
217
    }
218
  }
219
  //this.addFirstListener("wfs_GetFeature", this.setRequestParameters, this);
220

    
221
  /**
222
   * Method to get a list of queryable layers
223
   * @return the list with queryable layers
224
   */
225
  this.getQueryableLayers = function() {
226
    var listNodeArray = this.doc.selectNodes("/wmc:OWSContext/wmc:ResourceList/wmc:Layer[attribute::queryable='1']/wmc:Name");
227
    return listNodeArray;
228
  }
229

    
230
  /**
231
   * Method to get a list of all layers in the context doc
232
   * TBD: merge this with above, passing queryable as an optional boolean param?
233
   * @return the list with all layers
234
   */
235
  this.getAllLayers = function() {
236
    var listNodeArray = this.doc.selectNodes("/wmc:OWSContext/wmc:ResourceList/wmc:Layer");
237
    return listNodeArray;
238
  }
239

    
240
  /**
241
   * Method to get a layer with the specified name in the context doc
242
   * @param layerName the layer to be returned
243
   * @return the list with all layers
244
   */
245
  this.getLayer = function(layerName) {
246
    var layer = this.doc.selectSingleNode("/wmc:OWSContext/wmc:ResourceList/wmc:Layer[wmc:Name='"+layerName+"']");
247
    //TBD: add in time stamp
248
    return layer;
249
  }
250

    
251

    
252
}
253

    
(12-12/18)