1
|
/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
|
2
|
* full list of contributors). Published under the 2-clause BSD license.
|
3
|
* See license.txt in the OpenLayers distribution or repository 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
|
|
70
|
/**
|
71
|
* APIMethod: read
|
72
|
* Parse a GetFeatureOfInterest response and return an array of features
|
73
|
*
|
74
|
* Parameters:
|
75
|
* data - {String} or {DOMElement} data to read/parse.
|
76
|
*
|
77
|
* Returns:
|
78
|
* {Array(<OpenLayers.Feature.Vector>)} An array of features.
|
79
|
*/
|
80
|
read: function(data) {
|
81
|
if(typeof data == "string") {
|
82
|
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
83
|
}
|
84
|
if(data && data.nodeType == 9) {
|
85
|
data = data.documentElement;
|
86
|
}
|
87
|
|
88
|
var info = {features: []};
|
89
|
this.readNode(data, info);
|
90
|
|
91
|
var features = [];
|
92
|
for (var i=0, len=info.features.length; i<len; i++) {
|
93
|
var container = info.features[i];
|
94
|
// reproject features if needed
|
95
|
if(this.internalProjection && this.externalProjection &&
|
96
|
container.components[0]) {
|
97
|
container.components[0].transform(
|
98
|
this.externalProjection, this.internalProjection
|
99
|
);
|
100
|
}
|
101
|
var feature = new OpenLayers.Feature.Vector(
|
102
|
container.components[0], container.attributes);
|
103
|
features.push(feature);
|
104
|
}
|
105
|
return features;
|
106
|
},
|
107
|
|
108
|
/**
|
109
|
* Property: readers
|
110
|
* Contains public functions, grouped by namespace prefix, that will
|
111
|
* be applied when a namespaced node is found matching the function
|
112
|
* name. The function will be applied in the scope of this parser
|
113
|
* with two arguments: the node being read and a context object passed
|
114
|
* from the parent.
|
115
|
*/
|
116
|
readers: {
|
117
|
"sa": {
|
118
|
"SamplingPoint": function(node, obj) {
|
119
|
// sampling point can also be without a featureMember if
|
120
|
// there is only 1
|
121
|
if (!obj.attributes) {
|
122
|
var feature = {attributes: {}};
|
123
|
obj.features.push(feature);
|
124
|
obj = feature;
|
125
|
}
|
126
|
obj.attributes.id = this.getAttributeNS(node,
|
127
|
this.namespaces.gml, "id");
|
128
|
this.readChildNodes(node, obj);
|
129
|
},
|
130
|
"position": function (node, obj) {
|
131
|
this.readChildNodes(node, obj);
|
132
|
}
|
133
|
},
|
134
|
"gml": OpenLayers.Util.applyDefaults({
|
135
|
"FeatureCollection": function(node, obj) {
|
136
|
this.readChildNodes(node, obj);
|
137
|
},
|
138
|
"featureMember": function(node, obj) {
|
139
|
var feature = {attributes: {}};
|
140
|
obj.features.push(feature);
|
141
|
this.readChildNodes(node, feature);
|
142
|
},
|
143
|
"name": function(node, obj) {
|
144
|
obj.attributes.name = this.getChildValue(node);
|
145
|
},
|
146
|
"pos": function(node, obj) {
|
147
|
// we need to parse the srsName to get to the
|
148
|
// externalProjection, that's why we cannot use
|
149
|
// GML v3 for this
|
150
|
if (!this.externalProjection) {
|
151
|
this.externalProjection = new OpenLayers.Projection(
|
152
|
node.getAttribute("srsName"));
|
153
|
}
|
154
|
OpenLayers.Format.GML.v3.prototype.readers.gml.pos.apply(
|
155
|
this, [node, obj]);
|
156
|
}
|
157
|
}, OpenLayers.Format.GML.v3.prototype.readers.gml)
|
158
|
},
|
159
|
|
160
|
/**
|
161
|
* Property: writers
|
162
|
* As a compliment to the readers property, this structure contains public
|
163
|
* writing functions grouped by namespace alias and named like the
|
164
|
* node names they produce.
|
165
|
*/
|
166
|
writers: {
|
167
|
"sos": {
|
168
|
"GetFeatureOfInterest": function(options) {
|
169
|
var node = this.createElementNSPlus("GetFeatureOfInterest", {
|
170
|
attributes: {
|
171
|
version: this.VERSION,
|
172
|
service: 'SOS',
|
173
|
"xsi:schemaLocation": this.schemaLocation
|
174
|
}
|
175
|
});
|
176
|
for (var i=0, len=options.fois.length; i<len; i++) {
|
177
|
this.writeNode("FeatureOfInterestId", {foi: options.fois[i]}, node);
|
178
|
}
|
179
|
return node;
|
180
|
},
|
181
|
"FeatureOfInterestId": function(options) {
|
182
|
var node = this.createElementNSPlus("FeatureOfInterestId", {value: options.foi});
|
183
|
return node;
|
184
|
}
|
185
|
}
|
186
|
},
|
187
|
|
188
|
CLASS_NAME: "OpenLayers.Format.SOSGetFeatureOfInterest"
|
189
|
|
190
|
});
|