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/WFST/v1.js
|
8
|
* @requires OpenLayers/Format/Filter/v1_1_0.js
|
9
|
* @requires OpenLayers/Format/OWSCommon/v1_0_0.js
|
10
|
*/
|
11
|
|
12
|
/**
|
13
|
* Class: OpenLayers.Format.WFST.v1_1_0
|
14
|
* A format for creating WFS v1.1.0 transactions. Create a new instance with the
|
15
|
* <OpenLayers.Format.WFST.v1_1_0> constructor.
|
16
|
*
|
17
|
* Inherits from:
|
18
|
* - <OpenLayers.Format.Filter.v1_1_0>
|
19
|
* - <OpenLayers.Format.WFST.v1>
|
20
|
*/
|
21
|
OpenLayers.Format.WFST.v1_1_0 = OpenLayers.Class(
|
22
|
OpenLayers.Format.Filter.v1_1_0, OpenLayers.Format.WFST.v1, {
|
23
|
|
24
|
/**
|
25
|
* Property: version
|
26
|
* {String} WFS version number.
|
27
|
*/
|
28
|
version: "1.1.0",
|
29
|
|
30
|
/**
|
31
|
* Property: schemaLocations
|
32
|
* {Object} Properties are namespace aliases, values are schema locations.
|
33
|
*/
|
34
|
schemaLocations: {
|
35
|
"wfs": "http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"
|
36
|
},
|
37
|
|
38
|
/**
|
39
|
* Constructor: OpenLayers.Format.WFST.v1_1_0
|
40
|
* A class for parsing and generating WFS v1.1.0 transactions.
|
41
|
*
|
42
|
* To read additional information like hit count (numberOfFeatures) from
|
43
|
* the FeatureCollection, call the <OpenLayers.Format.WFST.v1.read> method
|
44
|
* with {output: "object"} as 2nd argument. Note that it is possible to
|
45
|
* just request the hit count from a WFS 1.1.0 server with the
|
46
|
* resultType="hits" request parameter.
|
47
|
*
|
48
|
* Parameters:
|
49
|
* options - {Object} Optional object whose properties will be set on the
|
50
|
* instance.
|
51
|
*
|
52
|
* Valid options properties:
|
53
|
* featureType - {String} Local (without prefix) feature typeName (required).
|
54
|
* featureNS - {String} Feature namespace (optional).
|
55
|
* featurePrefix - {String} Feature namespace alias (optional - only used
|
56
|
* if featureNS is provided). Default is 'feature'.
|
57
|
* geometryName - {String} Name of geometry attribute. Default is 'the_geom'.
|
58
|
*/
|
59
|
initialize: function(options) {
|
60
|
OpenLayers.Format.Filter.v1_1_0.prototype.initialize.apply(this, [options]);
|
61
|
OpenLayers.Format.WFST.v1.prototype.initialize.apply(this, [options]);
|
62
|
},
|
63
|
|
64
|
/**
|
65
|
* Method: readNode
|
66
|
* Shorthand for applying one of the named readers given the node
|
67
|
* namespace and local name. Readers take two args (node, obj) and
|
68
|
* generally extend or modify the second.
|
69
|
*
|
70
|
* Parameters:
|
71
|
* node - {DOMElement} The node to be read (required).
|
72
|
* obj - {Object} The object to be modified (optional).
|
73
|
* first - {Boolean} Should be set to true for the first node read. This
|
74
|
* is usually the readNode call in the read method. Without this being
|
75
|
* set, auto-configured properties will stick on subsequent reads.
|
76
|
*
|
77
|
* Returns:
|
78
|
* {Object} The input object, modified (or a new one if none was provided).
|
79
|
*/
|
80
|
readNode: function(node, obj, first) {
|
81
|
// Not the superclass, only the mixin classes inherit from
|
82
|
// Format.GML.v3. We need this because we don't want to get readNode
|
83
|
// from the superclass's superclass, which is OpenLayers.Format.XML.
|
84
|
return OpenLayers.Format.GML.v3.prototype.readNode.apply(this, arguments);
|
85
|
},
|
86
|
|
87
|
/**
|
88
|
* Property: readers
|
89
|
* Contains public functions, grouped by namespace prefix, that will
|
90
|
* be applied when a namespaced node is found matching the function
|
91
|
* name. The function will be applied in the scope of this parser
|
92
|
* with two arguments: the node being read and a context object passed
|
93
|
* from the parent.
|
94
|
*/
|
95
|
readers: {
|
96
|
"wfs": OpenLayers.Util.applyDefaults({
|
97
|
"FeatureCollection": function(node, obj) {
|
98
|
obj.numberOfFeatures = parseInt(node.getAttribute(
|
99
|
"numberOfFeatures"));
|
100
|
OpenLayers.Format.WFST.v1.prototype.readers["wfs"]["FeatureCollection"].apply(
|
101
|
this, arguments);
|
102
|
},
|
103
|
"TransactionResponse": function(node, obj) {
|
104
|
obj.insertIds = [];
|
105
|
obj.success = false;
|
106
|
this.readChildNodes(node, obj);
|
107
|
},
|
108
|
"TransactionSummary": function(node, obj) {
|
109
|
// this is a limited test of success
|
110
|
obj.success = true;
|
111
|
},
|
112
|
"InsertResults": function(node, obj) {
|
113
|
this.readChildNodes(node, obj);
|
114
|
},
|
115
|
"Feature": function(node, container) {
|
116
|
var obj = {fids: []};
|
117
|
this.readChildNodes(node, obj);
|
118
|
container.insertIds.push(obj.fids[0]);
|
119
|
}
|
120
|
}, OpenLayers.Format.WFST.v1.prototype.readers["wfs"]),
|
121
|
"gml": OpenLayers.Format.GML.v3.prototype.readers["gml"],
|
122
|
"feature": OpenLayers.Format.GML.v3.prototype.readers["feature"],
|
123
|
"ogc": OpenLayers.Format.Filter.v1_1_0.prototype.readers["ogc"],
|
124
|
"ows": OpenLayers.Format.OWSCommon.v1_0_0.prototype.readers["ows"]
|
125
|
},
|
126
|
|
127
|
/**
|
128
|
* Property: writers
|
129
|
* As a compliment to the readers property, this structure contains public
|
130
|
* writing functions grouped by namespace alias and named like the
|
131
|
* node names they produce.
|
132
|
*/
|
133
|
writers: {
|
134
|
"wfs": OpenLayers.Util.applyDefaults({
|
135
|
"GetFeature": function(options) {
|
136
|
var node = OpenLayers.Format.WFST.v1.prototype.writers["wfs"]["GetFeature"].apply(this, arguments);
|
137
|
options && this.setAttributes(node, {
|
138
|
resultType: options.resultType,
|
139
|
startIndex: options.startIndex,
|
140
|
count: options.count
|
141
|
});
|
142
|
return node;
|
143
|
},
|
144
|
"Query": function(options) {
|
145
|
options = OpenLayers.Util.extend({
|
146
|
featureNS: this.featureNS,
|
147
|
featurePrefix: this.featurePrefix,
|
148
|
featureType: this.featureType,
|
149
|
srsName: this.srsName
|
150
|
}, options);
|
151
|
var prefix = options.featurePrefix;
|
152
|
var node = this.createElementNSPlus("wfs:Query", {
|
153
|
attributes: {
|
154
|
typeName: (prefix ? prefix + ":" : "") +
|
155
|
options.featureType,
|
156
|
srsName: options.srsName
|
157
|
}
|
158
|
});
|
159
|
if(options.featureNS) {
|
160
|
node.setAttribute("xmlns:" + prefix, options.featureNS);
|
161
|
}
|
162
|
if(options.propertyNames) {
|
163
|
for(var i=0,len = options.propertyNames.length; i<len; i++) {
|
164
|
this.writeNode(
|
165
|
"wfs:PropertyName",
|
166
|
{property: options.propertyNames[i]},
|
167
|
node
|
168
|
);
|
169
|
}
|
170
|
}
|
171
|
if(options.filter) {
|
172
|
OpenLayers.Format.WFST.v1_1_0.prototype.setFilterProperty.call(this, options.filter);
|
173
|
this.writeNode("ogc:Filter", options.filter, node);
|
174
|
}
|
175
|
return node;
|
176
|
},
|
177
|
"PropertyName": function(obj) {
|
178
|
return this.createElementNSPlus("wfs:PropertyName", {
|
179
|
value: obj.property
|
180
|
});
|
181
|
}
|
182
|
}, OpenLayers.Format.WFST.v1.prototype.writers["wfs"]),
|
183
|
"gml": OpenLayers.Format.GML.v3.prototype.writers["gml"],
|
184
|
"feature": OpenLayers.Format.GML.v3.prototype.writers["feature"],
|
185
|
"ogc": OpenLayers.Format.Filter.v1_1_0.prototype.writers["ogc"]
|
186
|
},
|
187
|
|
188
|
CLASS_NAME: "OpenLayers.Format.WFST.v1_1_0"
|
189
|
});
|