1 | /* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for |
---|
2 | * full list of contributors). Published under the Clear BSD license. |
---|
3 | * See http://svn.openlayers.org/trunk/openlayers/license.txt for the |
---|
4 | * full text of the license. */ |
---|
5 | |
---|
6 | /** |
---|
7 | * @requires OpenLayers/Format/XML.js |
---|
8 | * @requires OpenLayers/Format/GML.js |
---|
9 | * @requires OpenLayers/Format/GML/v3.js |
---|
10 | */ |
---|
11 | |
---|
12 | /** |
---|
13 | * Class: OpenLayers.Format.SOSGetObservation |
---|
14 | * Read and write SOS GetObersation (to get the actual values from a sensor) |
---|
15 | * version 1.0.0 |
---|
16 | * |
---|
17 | * Inherits from: |
---|
18 | * - <OpenLayers.Format.XML> |
---|
19 | */ |
---|
20 | OpenLayers.Format.SOSGetObservation = OpenLayers.Class(OpenLayers.Format.XML, { |
---|
21 | |
---|
22 | /** |
---|
23 | * Property: namespaces |
---|
24 | * {Object} Mapping of namespace aliases to namespace URIs. |
---|
25 | */ |
---|
26 | namespaces: { |
---|
27 | ows: "http://www.opengis.net/ows", |
---|
28 | gml: "http://www.opengis.net/gml", |
---|
29 | sos: "http://www.opengis.net/sos/1.0", |
---|
30 | ogc: "http://www.opengis.net/ogc", |
---|
31 | om: "http://www.opengis.net/om/1.0", |
---|
32 | xlink: "http://www.w3.org/1999/xlink", |
---|
33 | xsi: "http://www.w3.org/2001/XMLSchema-instance" |
---|
34 | }, |
---|
35 | |
---|
36 | /** |
---|
37 | * Property: regExes |
---|
38 | * Compiled regular expressions for manipulating strings. |
---|
39 | */ |
---|
40 | regExes: { |
---|
41 | trimSpace: (/^\s*|\s*$/g), |
---|
42 | removeSpace: (/\s*/g), |
---|
43 | splitSpace: (/\s+/), |
---|
44 | trimComma: (/\s*,\s*/g) |
---|
45 | }, |
---|
46 | |
---|
47 | /** |
---|
48 | * Constant: VERSION |
---|
49 | * {String} 1.0.0 |
---|
50 | */ |
---|
51 | VERSION: "1.0.0", |
---|
52 | |
---|
53 | /** |
---|
54 | * Property: schemaLocation |
---|
55 | * {String} Schema location |
---|
56 | */ |
---|
57 | schemaLocation: "http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosGetObservation.xsd", |
---|
58 | |
---|
59 | /** |
---|
60 | * Property: defaultPrefix |
---|
61 | */ |
---|
62 | defaultPrefix: "sos", |
---|
63 | |
---|
64 | /** |
---|
65 | * Constructor: OpenLayers.Format.SOSGetObservation |
---|
66 | * |
---|
67 | * Parameters: |
---|
68 | * options - {Object} An optional object whose properties will be set on |
---|
69 | * this instance. |
---|
70 | */ |
---|
71 | initialize: function(options) { |
---|
72 | OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); |
---|
73 | }, |
---|
74 | |
---|
75 | /** |
---|
76 | * Method: read |
---|
77 | * |
---|
78 | * Parameters: |
---|
79 | * data - {String} or {DOMElement} data to read/parse. |
---|
80 | * |
---|
81 | * Returns: |
---|
82 | * {Object} An object containing the measurements |
---|
83 | */ |
---|
84 | read: function(data) { |
---|
85 | if(typeof data == "string") { |
---|
86 | data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); |
---|
87 | } |
---|
88 | if(data && data.nodeType == 9) { |
---|
89 | data = data.documentElement; |
---|
90 | } |
---|
91 | var info = {measurements: []}; |
---|
92 | this.readNode(data, info); |
---|
93 | return info; |
---|
94 | }, |
---|
95 | |
---|
96 | /** |
---|
97 | * Method: write |
---|
98 | * |
---|
99 | * Parameters: |
---|
100 | * options - {Object} Optional object. |
---|
101 | * |
---|
102 | * Returns: |
---|
103 | * {String} An SOS GetObservation request XML string. |
---|
104 | */ |
---|
105 | write: function(options) { |
---|
106 | var node = this.writeNode("sos:GetObservation", options); |
---|
107 | node.setAttribute("xmlns:om", this.namespaces.om); |
---|
108 | this.setAttributeNS( |
---|
109 | node, this.namespaces.xsi, |
---|
110 | "xsi:schemaLocation", this.schemaLocation |
---|
111 | ); |
---|
112 | return OpenLayers.Format.XML.prototype.write.apply(this, [node]); |
---|
113 | }, |
---|
114 | |
---|
115 | /** |
---|
116 | * Property: readers |
---|
117 | * Contains public functions, grouped by namespace prefix, that will |
---|
118 | * be applied when a namespaced node is found matching the function |
---|
119 | * name. The function will be applied in the scope of this parser |
---|
120 | * with two arguments: the node being read and a context object passed |
---|
121 | * from the parent. |
---|
122 | */ |
---|
123 | readers: { |
---|
124 | "om": { |
---|
125 | "ObservationCollection": function(node, obj) { |
---|
126 | obj.id = this.getAttributeNS(node, this.namespaces.gml, "id"); |
---|
127 | this.readChildNodes(node, obj); |
---|
128 | }, |
---|
129 | "member": function(node, observationCollection) { |
---|
130 | this.readChildNodes(node, observationCollection); |
---|
131 | }, |
---|
132 | "Measurement": function(node, observationCollection) { |
---|
133 | var measurement = {}; |
---|
134 | observationCollection.measurements.push(measurement); |
---|
135 | this.readChildNodes(node, measurement); |
---|
136 | }, |
---|
137 | "samplingTime": function(node, measurement) { |
---|
138 | var samplingTime = {}; |
---|
139 | measurement.samplingTime = samplingTime; |
---|
140 | this.readChildNodes(node, samplingTime); |
---|
141 | }, |
---|
142 | "observedProperty": function(node, measurement) { |
---|
143 | measurement.observedProperty = |
---|
144 | this.getAttributeNS(node, this.namespaces.xlink, "href"); |
---|
145 | this.readChildNodes(node, measurement); |
---|
146 | }, |
---|
147 | "procedure": function(node, measurement) { |
---|
148 | measurement.procedure = |
---|
149 | this.getAttributeNS(node, this.namespaces.xlink, "href"); |
---|
150 | this.readChildNodes(node, measurement); |
---|
151 | }, |
---|
152 | "result": function(node, measurement) { |
---|
153 | var result = {}; |
---|
154 | measurement.result = result; |
---|
155 | if (this.getChildValue(node) !== '') { |
---|
156 | result.value = this.getChildValue(node); |
---|
157 | result.uom = node.getAttribute("uom"); |
---|
158 | } else { |
---|
159 | this.readChildNodes(node, result); |
---|
160 | } |
---|
161 | } |
---|
162 | }, |
---|
163 | "gml": OpenLayers.Util.applyDefaults({ |
---|
164 | "TimeInstant": function(node, samplingTime) { |
---|
165 | var timeInstant = {}; |
---|
166 | samplingTime.timeInstant = timeInstant; |
---|
167 | this.readChildNodes(node, timeInstant); |
---|
168 | }, |
---|
169 | "timePosition": function(node, timeInstant) { |
---|
170 | timeInstant.timePosition = this.getChildValue(node); |
---|
171 | } |
---|
172 | }, OpenLayers.Format.GML.v3.prototype.readers.gml) |
---|
173 | }, |
---|
174 | |
---|
175 | /** |
---|
176 | * Property: writers |
---|
177 | * As a compliment to the readers property, this structure contains public |
---|
178 | * writing functions grouped by namespace alias and named like the |
---|
179 | * node names they produce. |
---|
180 | */ |
---|
181 | writers: { |
---|
182 | "sos": { |
---|
183 | "GetObservation": function(options) { |
---|
184 | var node = this.createElementNSPlus("GetObservation", { |
---|
185 | attributes: { |
---|
186 | version: this.VERSION, |
---|
187 | service: 'SOS' |
---|
188 | } |
---|
189 | }); |
---|
190 | this.writeNode("offering", options, node); |
---|
191 | this.writeNode("eventTime", options, node); |
---|
192 | this.writeNode("procedure", options, node); |
---|
193 | this.writeNode("observedProperty", options, node); |
---|
194 | this.writeNode("responseFormat", options, node); |
---|
195 | this.writeNode("resultModel", options, node); |
---|
196 | this.writeNode("responseMode", options, node); |
---|
197 | return node; |
---|
198 | }, |
---|
199 | "responseFormat": function(options) { |
---|
200 | return this.createElementNSPlus("responseFormat", |
---|
201 | {value: options.responseFormat}); |
---|
202 | }, |
---|
203 | "procedure": function(options) { |
---|
204 | return this.createElementNSPlus("procedure", |
---|
205 | {value: options.procedure}); |
---|
206 | }, |
---|
207 | "offering": function(options) { |
---|
208 | return this.createElementNSPlus("offering", {value: |
---|
209 | options.offering}); |
---|
210 | }, |
---|
211 | "observedProperty": function(options) { |
---|
212 | return this.createElementNSPlus("observedProperty", |
---|
213 | {value: options.observedProperty}); |
---|
214 | }, |
---|
215 | "eventTime": function(options) { |
---|
216 | var node = this.createElementNSPlus("eventTime"); |
---|
217 | if (options.eventTime === 'latest') { |
---|
218 | this.writeNode("ogc:TM_Equals", options, node); |
---|
219 | } |
---|
220 | return node; |
---|
221 | }, |
---|
222 | "resultModel": function(options) { |
---|
223 | return this.createElementNSPlus("resultModel", {value: |
---|
224 | options.resultModel}); |
---|
225 | }, |
---|
226 | "responseMode": function(options) { |
---|
227 | return this.createElementNSPlus("responseMode", {value: |
---|
228 | options.responseMode}); |
---|
229 | } |
---|
230 | }, |
---|
231 | "ogc": { |
---|
232 | "TM_Equals": function(options) { |
---|
233 | var node = this.createElementNSPlus("ogc:TM_Equals"); |
---|
234 | this.writeNode("ogc:PropertyName", {property: |
---|
235 | "urn:ogc:data:time:iso8601"}, node); |
---|
236 | if (options.eventTime === 'latest') { |
---|
237 | this.writeNode("gml:TimeInstant", {value: 'latest'}, node); |
---|
238 | } |
---|
239 | return node; |
---|
240 | }, |
---|
241 | "PropertyName": function(options) { |
---|
242 | return this.createElementNSPlus("ogc:PropertyName", |
---|
243 | {value: options.property}); |
---|
244 | } |
---|
245 | }, |
---|
246 | "gml": { |
---|
247 | "TimeInstant": function(options) { |
---|
248 | var node = this.createElementNSPlus("gml:TimeInstant"); |
---|
249 | this.writeNode("gml:timePosition", options, node); |
---|
250 | return node; |
---|
251 | }, |
---|
252 | "timePosition": function(options) { |
---|
253 | var node = this.createElementNSPlus("gml:timePosition", |
---|
254 | {value: options.value}); |
---|
255 | return node; |
---|
256 | } |
---|
257 | } |
---|
258 | }, |
---|
259 | |
---|
260 | CLASS_NAME: "OpenLayers.Format.SOSGetObservation" |
---|
261 | |
---|
262 | }); |
---|