[76] | 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/v3.js |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | /** |
---|
| 12 | * Class: OpenLayers.Format.SOSGetFeatureOfInterest |
---|
| 13 | * Read and write SOS GetFeatureOfInterest. This is used to get to |
---|
| 14 | * the location of the features (stations). The stations can have 1 or more |
---|
| 15 | * sensors. |
---|
| 16 | * |
---|
| 17 | * Inherits from: |
---|
| 18 | * - <OpenLayers.Format.XML> |
---|
| 19 | */ |
---|
| 20 | OpenLayers.Format.SOSGetFeatureOfInterest = OpenLayers.Class( |
---|
| 21 | OpenLayers.Format.XML, { |
---|
| 22 | |
---|
| 23 | /** |
---|
| 24 | * Constant: VERSION |
---|
| 25 | * {String} 1.0.0 |
---|
| 26 | */ |
---|
| 27 | VERSION: "1.0.0", |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | * Property: namespaces |
---|
| 31 | * {Object} Mapping of namespace aliases to namespace URIs. |
---|
| 32 | */ |
---|
| 33 | namespaces: { |
---|
| 34 | sos: "http://www.opengis.net/sos/1.0", |
---|
| 35 | gml: "http://www.opengis.net/gml", |
---|
| 36 | sa: "http://www.opengis.net/sampling/1.0", |
---|
| 37 | xsi: "http://www.w3.org/2001/XMLSchema-instance" |
---|
| 38 | }, |
---|
| 39 | |
---|
| 40 | /** |
---|
| 41 | * Property: schemaLocation |
---|
| 42 | * {String} Schema location |
---|
| 43 | */ |
---|
| 44 | schemaLocation: "http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosAll.xsd", |
---|
| 45 | |
---|
| 46 | /** |
---|
| 47 | * Property: defaultPrefix |
---|
| 48 | */ |
---|
| 49 | defaultPrefix: "sos", |
---|
| 50 | |
---|
| 51 | /** |
---|
| 52 | * Property: regExes |
---|
| 53 | * Compiled regular expressions for manipulating strings. |
---|
| 54 | */ |
---|
| 55 | regExes: { |
---|
| 56 | trimSpace: (/^\s*|\s*$/g), |
---|
| 57 | removeSpace: (/\s*/g), |
---|
| 58 | splitSpace: (/\s+/), |
---|
| 59 | trimComma: (/\s*,\s*/g) |
---|
| 60 | }, |
---|
| 61 | |
---|
| 62 | /** |
---|
| 63 | * Constructor: OpenLayers.Format.SOSGetFeatureOfInterest |
---|
| 64 | * |
---|
| 65 | * Parameters: |
---|
| 66 | * options - {Object} An optional object whose properties will be set on |
---|
| 67 | * this instance. |
---|
| 68 | */ |
---|
| 69 | initialize: function(options) { |
---|
| 70 | OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); |
---|
| 71 | }, |
---|
| 72 | |
---|
| 73 | /** |
---|
| 74 | * APIMethod: read |
---|
| 75 | * Parse a GetFeatureOfInterest response and return an array of features |
---|
| 76 | * |
---|
| 77 | * Parameters: |
---|
| 78 | * data - {String} or {DOMElement} data to read/parse. |
---|
| 79 | * |
---|
| 80 | * Returns: |
---|
| 81 | * {Array(<OpenLayers.Feature.Vector>)} An array of features. |
---|
| 82 | */ |
---|
| 83 | read: function(data) { |
---|
| 84 | if(typeof data == "string") { |
---|
| 85 | data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); |
---|
| 86 | } |
---|
| 87 | if(data && data.nodeType == 9) { |
---|
| 88 | data = data.documentElement; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | var info = {features: []}; |
---|
| 92 | this.readNode(data, info); |
---|
| 93 | |
---|
| 94 | var features = []; |
---|
| 95 | for (var i=0, len=info.features.length; i<len; i++) { |
---|
| 96 | var container = info.features[i]; |
---|
| 97 | // reproject features if needed |
---|
| 98 | if(this.internalProjection && this.externalProjection && |
---|
| 99 | container.components[0]) { |
---|
| 100 | container.components[0].transform( |
---|
| 101 | this.externalProjection, this.internalProjection |
---|
| 102 | ); |
---|
| 103 | } |
---|
| 104 | var feature = new OpenLayers.Feature.Vector( |
---|
| 105 | container.components[0], container.attributes); |
---|
| 106 | features.push(feature); |
---|
| 107 | } |
---|
| 108 | return features; |
---|
| 109 | }, |
---|
| 110 | |
---|
| 111 | /** |
---|
| 112 | * Property: readers |
---|
| 113 | * Contains public functions, grouped by namespace prefix, that will |
---|
| 114 | * be applied when a namespaced node is found matching the function |
---|
| 115 | * name. The function will be applied in the scope of this parser |
---|
| 116 | * with two arguments: the node being read and a context object passed |
---|
| 117 | * from the parent. |
---|
| 118 | */ |
---|
| 119 | readers: { |
---|
| 120 | "sa": { |
---|
| 121 | "SamplingPoint": function(node, obj) { |
---|
| 122 | // sampling point can also be without a featureMember if |
---|
| 123 | // there is only 1 |
---|
| 124 | if (!obj.attributes) { |
---|
| 125 | var feature = {attributes: {}}; |
---|
| 126 | obj.features.push(feature); |
---|
| 127 | obj = feature; |
---|
| 128 | } |
---|
| 129 | obj.attributes.id = this.getAttributeNS(node, |
---|
| 130 | this.namespaces.gml, "id"); |
---|
| 131 | this.readChildNodes(node, obj); |
---|
| 132 | }, |
---|
| 133 | "position": function (node, obj) { |
---|
| 134 | this.readChildNodes(node, obj); |
---|
| 135 | } |
---|
| 136 | }, |
---|
| 137 | "gml": OpenLayers.Util.applyDefaults({ |
---|
| 138 | "FeatureCollection": function(node, obj) { |
---|
| 139 | this.readChildNodes(node, obj); |
---|
| 140 | }, |
---|
| 141 | "featureMember": function(node, obj) { |
---|
| 142 | var feature = {attributes: {}}; |
---|
| 143 | obj.features.push(feature); |
---|
| 144 | this.readChildNodes(node, feature); |
---|
| 145 | }, |
---|
| 146 | "name": function(node, obj) { |
---|
| 147 | obj.attributes.name = this.getChildValue(node); |
---|
| 148 | }, |
---|
| 149 | "pos": function(node, obj) { |
---|
| 150 | // we need to parse the srsName to get to the |
---|
| 151 | // externalProjection, that's why we cannot use |
---|
| 152 | // GML v3 for this |
---|
| 153 | if (!this.externalProjection) { |
---|
| 154 | this.externalProjection = new OpenLayers.Projection( |
---|
| 155 | node.getAttribute("srsName")); |
---|
| 156 | } |
---|
| 157 | OpenLayers.Format.GML.v3.prototype.readers.gml.pos.apply( |
---|
| 158 | this, [node, obj]); |
---|
| 159 | } |
---|
| 160 | }, OpenLayers.Format.GML.v3.prototype.readers.gml) |
---|
| 161 | }, |
---|
| 162 | |
---|
| 163 | /** |
---|
| 164 | * Property: writers |
---|
| 165 | * As a compliment to the readers property, this structure contains public |
---|
| 166 | * writing functions grouped by namespace alias and named like the |
---|
| 167 | * node names they produce. |
---|
| 168 | */ |
---|
| 169 | writers: { |
---|
| 170 | "sos": { |
---|
| 171 | "GetFeatureOfInterest": function(options) { |
---|
| 172 | var node = this.createElementNSPlus("GetFeatureOfInterest", { |
---|
| 173 | attributes: { |
---|
| 174 | version: this.VERSION, |
---|
| 175 | service: 'SOS', |
---|
| 176 | "xsi:schemaLocation": this.schemaLocation |
---|
| 177 | } |
---|
| 178 | }); |
---|
| 179 | for (var i=0, len=options.fois.length; i<len; i++) { |
---|
| 180 | this.writeNode("FeatureOfInterestId", {foi: options.fois[i]}, node); |
---|
| 181 | } |
---|
| 182 | return node; |
---|
| 183 | }, |
---|
| 184 | "FeatureOfInterestId": function(options) { |
---|
| 185 | var node = this.createElementNSPlus("FeatureOfInterestId", {value: options.foi}); |
---|
| 186 | return node; |
---|
| 187 | } |
---|
| 188 | } |
---|
| 189 | }, |
---|
| 190 | |
---|
| 191 | CLASS_NAME: "OpenLayers.Format.SOSGetFeatureOfInterest" |
---|
| 192 | |
---|
| 193 | }); |
---|