6c44f5831eedecb2fee38bb5898ee048b2cd364e.svn-base
7.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
* full list of contributors). Published under the Clear BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Format/GML/v2.js
* @requires OpenLayers/Format/Filter/v1.js
*/
/**
* Class: OpenLayers.Format.Filter.v1_0_0
* Write ogc:Filter version 1.0.0.
*
* Inherits from:
* - <OpenLayers.Format.GML.v2>
* - <OpenLayers.Format.Filter.v1>
*/
OpenLayers.Format.Filter.v1_0_0 = OpenLayers.Class(
OpenLayers.Format.GML.v2, OpenLayers.Format.Filter.v1, {
/**
* Constant: VERSION
* {String} 1.0.0
*/
VERSION: "1.0.0",
/**
* Property: schemaLocation
* {String} http://www.opengis.net/ogc/filter/1.0.0/filter.xsd
*/
schemaLocation: "http://www.opengis.net/ogc/filter/1.0.0/filter.xsd",
/**
* Constructor: OpenLayers.Format.Filter.v1_0_0
* Instances of this class are not created directly. Use the
* <OpenLayers.Format.Filter> constructor instead.
*
* Parameters:
* options - {Object} An optional object whose properties will be set on
* this instance.
*/
initialize: function(options) {
OpenLayers.Format.GML.v2.prototype.initialize.apply(
this, [options]
);
},
/**
* 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: {
"ogc": OpenLayers.Util.applyDefaults({
"PropertyIsEqualTo": function(node, obj) {
var filter = new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO
});
this.readChildNodes(node, filter);
obj.filters.push(filter);
},
"PropertyIsNotEqualTo": function(node, obj) {
var filter = new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO
});
this.readChildNodes(node, filter);
obj.filters.push(filter);
},
"PropertyIsLike": function(node, obj) {
var filter = new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.LIKE
});
this.readChildNodes(node, filter);
var wildCard = node.getAttribute("wildCard");
var singleChar = node.getAttribute("singleChar");
var esc = node.getAttribute("escape");
filter.value2regex(wildCard, singleChar, esc);
obj.filters.push(filter);
}
}, OpenLayers.Format.Filter.v1.prototype.readers["ogc"]),
"gml": OpenLayers.Format.GML.v2.prototype.readers["gml"],
"feature": OpenLayers.Format.GML.v2.prototype.readers["feature"]
},
/**
* Property: writers
* As a compliment to the readers property, this structure contains public
* writing functions grouped by namespace alias and named like the
* node names they produce.
*/
writers: {
"ogc": OpenLayers.Util.applyDefaults({
"PropertyIsEqualTo": function(filter) {
var node = this.createElementNSPlus("ogc:PropertyIsEqualTo");
// no ogc:expression handling for PropertyName for now
this.writeNode("PropertyName", filter, node);
// handle Literals or Functions for now
this.writeOgcExpression(filter.value, node);
return node;
},
"PropertyIsNotEqualTo": function(filter) {
var node = this.createElementNSPlus("ogc:PropertyIsNotEqualTo");
// no ogc:expression handling for PropertyName for now
this.writeNode("PropertyName", filter, node);
// handle Literals or Functions for now
this.writeOgcExpression(filter.value, node);
return node;
},
"PropertyIsLike": function(filter) {
var node = this.createElementNSPlus("ogc:PropertyIsLike", {
attributes: {
wildCard: "*", singleChar: ".", escape: "!"
}
});
// no ogc:expression handling for now
this.writeNode("PropertyName", filter, node);
// convert regex string to ogc string
this.writeNode("Literal", filter.regex2value(), node);
return node;
},
"BBOX": function(filter) {
var node = this.createElementNSPlus("ogc:BBOX");
// PropertyName is mandatory in 1.0.0, but e.g. GeoServer also
// accepts filters without it. When this is used with
// OpenLayers.Protocol.WFS, OpenLayers.Format.WFST will set a
// missing filter.property to the geometryName that is
// configured with the protocol, which defaults to "the_geom".
// So the only way to omit this mandatory property is to not
// set the property on the filter and to set the geometryName
// on the WFS protocol to null. The latter also happens when
// the protocol is configured without a geometryName and a
// featureNS.
filter.property && this.writeNode("PropertyName", filter, node);
var box = this.writeNode("gml:Box", filter.value, node);
if(filter.projection) {
box.setAttribute("srsName", filter.projection);
}
return node;
}
}, OpenLayers.Format.Filter.v1.prototype.writers["ogc"]),
"gml": OpenLayers.Format.GML.v2.prototype.writers["gml"],
"feature": OpenLayers.Format.GML.v2.prototype.writers["feature"]
},
/**
* Method: writeSpatial
*
* Read a {<OpenLayers.Filter.Spatial>} filter and converts it into XML.
*
* Parameters:
* filter - {<OpenLayers.Filter.Spatial>} The filter.
* name - {String} Name of the generated XML element.
*
* Returns:
* {DOMElement} The created XML element.
*/
writeSpatial: function(filter, name) {
var node = this.createElementNSPlus("ogc:"+name);
this.writeNode("PropertyName", filter, node);
if(filter.value instanceof OpenLayers.Filter.Function) {
this.writeNode("Function", filter.value, node);
} else {
var child;
if(filter.value instanceof OpenLayers.Geometry) {
child = this.writeNode("feature:_geometry", filter.value).firstChild;
} else {
child = this.writeNode("gml:Box", filter.value);
}
if(filter.projection) {
child.setAttribute("srsName", filter.projection);
}
node.appendChild(child);
}
return node;
},
CLASS_NAME: "OpenLayers.Format.Filter.v1_0_0"
});