1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2 * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3 * full text of the license. */
6 * @requires OpenLayers/Format/Filter/v1.js
7 * @requires OpenLayers/Format/GML/v3.js
11 * Class: OpenLayers.Format.Filter.v1_1_0
12 * Write ogc:Filter version 1.1.0.
14 * Differences from the v1.0.0 parser:
15 * - uses GML v3 instead of GML v2
16 * - reads matchCase attribute on ogc:PropertyIsEqual and
17 * ogc:PropertyIsNotEqualelements.
18 * - writes matchCase attribute from comparison filters of type EQUAL_TO and
22 * - <OpenLayers.Format.Filter.v1>
24 OpenLayers.Format.Filter.v1_1_0 = OpenLayers.Class(
25 OpenLayers.Format.GML.v3, OpenLayers.Format.Filter.v1, {
34 * Property: schemaLocation
35 * {String} http://www.opengis.net/ogc/filter/1.1.0/filter.xsd
37 schemaLocation: "http://www.opengis.net/ogc/filter/1.1.0/filter.xsd",
40 * Constructor: OpenLayers.Format.Filter.v1_1_0
41 * Instances of this class are not created directly. Use the
42 * <OpenLayers.Format.Filter> constructor instead.
45 * options - {Object} An optional object whose properties will be set on
48 initialize: function(options) {
49 OpenLayers.Format.GML.v3.prototype.initialize.apply(
56 * Contains public functions, grouped by namespace prefix, that will
57 * be applied when a namespaced node is found matching the function
58 * name. The function will be applied in the scope of this parser
59 * with two arguments: the node being read and a context object passed
63 "ogc": OpenLayers.Util.applyDefaults({
64 "PropertyIsEqualTo": function(node, obj) {
65 var matchCase = node.getAttribute("matchCase");
66 var filter = new OpenLayers.Filter.Comparison({
67 type: OpenLayers.Filter.Comparison.EQUAL_TO,
68 matchCase: !(matchCase === "false" || matchCase === "0")
70 this.readChildNodes(node, filter);
71 obj.filters.push(filter);
73 "PropertyIsNotEqualTo": function(node, obj) {
74 var matchCase = node.getAttribute("matchCase");
75 var filter = new OpenLayers.Filter.Comparison({
76 type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO,
77 matchCase: !(matchCase === "false" || matchCase === "0")
79 this.readChildNodes(node, filter);
80 obj.filters.push(filter);
82 }, OpenLayers.Format.Filter.v1.prototype.readers["ogc"]),
83 "gml": OpenLayers.Format.GML.v3.prototype.readers["gml"],
84 "feature": OpenLayers.Format.GML.v3.prototype.readers["feature"]
89 * As a compliment to the readers property, this structure contains public
90 * writing functions grouped by namespace alias and named like the
91 * node names they produce.
94 "ogc": OpenLayers.Util.applyDefaults({
95 "PropertyIsEqualTo": function(filter) {
96 var node = this.createElementNSPlus("ogc:PropertyIsEqualTo", {
97 attributes: {matchCase: filter.matchCase}
99 // no ogc:expression handling for now
100 this.writeNode("PropertyName", filter, node);
101 this.writeNode("Literal", filter.value, node);
104 "PropertyIsNotEqualTo": function(filter) {
105 var node = this.createElementNSPlus("ogc:PropertyIsNotEqualTo", {
106 attributes: {matchCase: filter.matchCase}
108 // no ogc:expression handling for now
109 this.writeNode("PropertyName", filter, node);
110 this.writeNode("Literal", filter.value, node);
113 "BBOX": function(filter) {
114 var node = this.createElementNSPlus("ogc:BBOX");
115 this.writeNode("PropertyName", filter, node);
116 var box = this.writeNode("gml:Envelope", filter.value);
117 if(filter.projection) {
118 box.setAttribute("srsName", filter.projection);
120 node.appendChild(box);
122 }}, OpenLayers.Format.Filter.v1.prototype.writers["ogc"]),
124 "gml": OpenLayers.Format.GML.v3.prototype.writers["gml"],
125 "feature": OpenLayers.Format.GML.v3.prototype.writers["feature"]
129 * Method: writeSpatial
131 * Read a {<OpenLayers.Filter.Spatial>} filter and converts it into XML.
134 * filter - {<OpenLayers.Filter.Spatial>} The filter.
135 * name - {String} Name of the generated XML element.
138 * {DOMElement} The created XML element.
140 writeSpatial: function(filter, name) {
141 var node = this.createElementNSPlus("ogc:"+name);
142 this.writeNode("PropertyName", filter, node);
144 if(filter.value instanceof OpenLayers.Geometry) {
145 child = this.writeNode("feature:_geometry", filter.value).firstChild;
147 child = this.writeNode("gml:Envelope", filter.value);
149 if(filter.projection) {
150 child.setAttribute("srsName", filter.projection);
152 node.appendChild(child);
156 CLASS_NAME: "OpenLayers.Format.Filter.v1_1_0"