/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for * full list of contributors). Published under the 2-clause BSD license. * See license.txt in the OpenLayers distribution or repository for the * full text of the license. */ /** * @requires OpenLayers/Format/XML.js * @requires OpenLayers/Format/SOSGetFeatureOfInterest.js */ /** * Class: OpenLayers.Format.SOSGetObservation * Read and write SOS GetObersation (to get the actual values from a sensor) * version 1.0.0 * * Inherits from: * - */ OpenLayers.Format.SOSGetObservation = OpenLayers.Class(OpenLayers.Format.XML, { /** * Property: namespaces * {Object} Mapping of namespace aliases to namespace URIs. */ namespaces: { ows: "http://www.opengis.net/ows", gml: "http://www.opengis.net/gml", sos: "http://www.opengis.net/sos/1.0", ogc: "http://www.opengis.net/ogc", om: "http://www.opengis.net/om/1.0", sa: "http://www.opengis.net/sampling/1.0", xlink: "http://www.w3.org/1999/xlink", xsi: "http://www.w3.org/2001/XMLSchema-instance" }, /** * Property: regExes * Compiled regular expressions for manipulating strings. */ regExes: { trimSpace: (/^\s*|\s*$/g), removeSpace: (/\s*/g), splitSpace: (/\s+/), trimComma: (/\s*,\s*/g) }, /** * Constant: VERSION * {String} 1.0.0 */ VERSION: "1.0.0", /** * Property: schemaLocation * {String} Schema location */ schemaLocation: "http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosGetObservation.xsd", /** * Property: defaultPrefix */ defaultPrefix: "sos", /** * Constructor: OpenLayers.Format.SOSGetObservation * * Parameters: * options - {Object} An optional object whose properties will be set on * this instance. */ /** * Method: read * * Parameters: * data - {String} or {DOMElement} data to read/parse. * * Returns: * {Object} An object containing the measurements */ read: function(data) { if(typeof data == "string") { data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); } if(data && data.nodeType == 9) { data = data.documentElement; } var info = {measurements: [], observations: []}; this.readNode(data, info); return info; }, /** * Method: write * * Parameters: * options - {Object} Optional object. * * Returns: * {String} An SOS GetObservation request XML string. */ write: function(options) { var node = this.writeNode("sos:GetObservation", options); node.setAttribute("xmlns:om", this.namespaces.om); node.setAttribute("xmlns:ogc", this.namespaces.ogc); this.setAttributeNS( node, this.namespaces.xsi, "xsi:schemaLocation", this.schemaLocation ); return OpenLayers.Format.XML.prototype.write.apply(this, [node]); }, /** * Property: readers * Contains public functions, grouped by namespace prefix, that will * be applied when a namespaced node is found matching the function * name. The function will be applied in the scope of this parser * with two arguments: the node being read and a context object passed * from the parent. */ readers: { "om": { "ObservationCollection": function(node, obj) { obj.id = this.getAttributeNS(node, this.namespaces.gml, "id"); this.readChildNodes(node, obj); }, "member": function(node, observationCollection) { this.readChildNodes(node, observationCollection); }, "Measurement": function(node, observationCollection) { var measurement = {}; observationCollection.measurements.push(measurement); this.readChildNodes(node, measurement); }, "Observation": function(node, observationCollection) { var observation = {}; observationCollection.observations.push(observation); this.readChildNodes(node, observation); }, "samplingTime": function(node, measurement) { var samplingTime = {}; measurement.samplingTime = samplingTime; this.readChildNodes(node, samplingTime); }, "observedProperty": function(node, measurement) { measurement.observedProperty = this.getAttributeNS(node, this.namespaces.xlink, "href"); this.readChildNodes(node, measurement); }, "procedure": function(node, measurement) { measurement.procedure = this.getAttributeNS(node, this.namespaces.xlink, "href"); this.readChildNodes(node, measurement); }, "featureOfInterest": function(node, observation) { var foi = {features: []}; observation.fois = []; observation.fois.push(foi); this.readChildNodes(node, foi); // postprocessing to get actual features var features = []; for (var i=0, len=foi.features.length; i