[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/GML/v2.js |
---|
| 8 | * @requires OpenLayers/Format/Filter/v1.js |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | /** |
---|
| 12 | * Class: OpenLayers.Format.Filter.v1_0_0 |
---|
| 13 | * Write ogc:Filter version 1.0.0. |
---|
| 14 | * |
---|
| 15 | * Inherits from: |
---|
| 16 | * - <OpenLayers.Format.GML.v2> |
---|
| 17 | * - <OpenLayers.Format.Filter.v1> |
---|
| 18 | */ |
---|
| 19 | OpenLayers.Format.Filter.v1_0_0 = OpenLayers.Class( |
---|
| 20 | OpenLayers.Format.GML.v2, OpenLayers.Format.Filter.v1, { |
---|
| 21 | |
---|
| 22 | /** |
---|
| 23 | * Constant: VERSION |
---|
| 24 | * {String} 1.0.0 |
---|
| 25 | */ |
---|
| 26 | VERSION: "1.0.0", |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * Property: schemaLocation |
---|
| 30 | * {String} http://www.opengis.net/ogc/filter/1.0.0/filter.xsd |
---|
| 31 | */ |
---|
| 32 | schemaLocation: "http://www.opengis.net/ogc/filter/1.0.0/filter.xsd", |
---|
| 33 | |
---|
| 34 | /** |
---|
| 35 | * Constructor: OpenLayers.Format.Filter.v1_0_0 |
---|
| 36 | * Instances of this class are not created directly. Use the |
---|
| 37 | * <OpenLayers.Format.Filter> constructor instead. |
---|
| 38 | * |
---|
| 39 | * Parameters: |
---|
| 40 | * options - {Object} An optional object whose properties will be set on |
---|
| 41 | * this instance. |
---|
| 42 | */ |
---|
| 43 | initialize: function(options) { |
---|
| 44 | OpenLayers.Format.GML.v2.prototype.initialize.apply( |
---|
| 45 | this, [options] |
---|
| 46 | ); |
---|
| 47 | }, |
---|
| 48 | |
---|
| 49 | /** |
---|
| 50 | * Property: readers |
---|
| 51 | * Contains public functions, grouped by namespace prefix, that will |
---|
| 52 | * be applied when a namespaced node is found matching the function |
---|
| 53 | * name. The function will be applied in the scope of this parser |
---|
| 54 | * with two arguments: the node being read and a context object passed |
---|
| 55 | * from the parent. |
---|
| 56 | */ |
---|
| 57 | readers: { |
---|
| 58 | "ogc": OpenLayers.Util.applyDefaults({ |
---|
| 59 | "PropertyIsEqualTo": function(node, obj) { |
---|
| 60 | var filter = new OpenLayers.Filter.Comparison({ |
---|
| 61 | type: OpenLayers.Filter.Comparison.EQUAL_TO |
---|
| 62 | }); |
---|
| 63 | this.readChildNodes(node, filter); |
---|
| 64 | obj.filters.push(filter); |
---|
| 65 | }, |
---|
| 66 | "PropertyIsNotEqualTo": function(node, obj) { |
---|
| 67 | var filter = new OpenLayers.Filter.Comparison({ |
---|
| 68 | type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO |
---|
| 69 | }); |
---|
| 70 | this.readChildNodes(node, filter); |
---|
| 71 | obj.filters.push(filter); |
---|
| 72 | }, |
---|
| 73 | "PropertyIsLike": function(node, obj) { |
---|
| 74 | var filter = new OpenLayers.Filter.Comparison({ |
---|
| 75 | type: OpenLayers.Filter.Comparison.LIKE |
---|
| 76 | }); |
---|
| 77 | this.readChildNodes(node, filter); |
---|
| 78 | var wildCard = node.getAttribute("wildCard"); |
---|
| 79 | var singleChar = node.getAttribute("singleChar"); |
---|
| 80 | var esc = node.getAttribute("escape"); |
---|
| 81 | filter.value2regex(wildCard, singleChar, esc); |
---|
| 82 | obj.filters.push(filter); |
---|
| 83 | } |
---|
| 84 | }, OpenLayers.Format.Filter.v1.prototype.readers["ogc"]), |
---|
| 85 | "gml": OpenLayers.Format.GML.v2.prototype.readers["gml"], |
---|
| 86 | "feature": OpenLayers.Format.GML.v2.prototype.readers["feature"] |
---|
| 87 | }, |
---|
| 88 | |
---|
| 89 | /** |
---|
| 90 | * Property: writers |
---|
| 91 | * As a compliment to the readers property, this structure contains public |
---|
| 92 | * writing functions grouped by namespace alias and named like the |
---|
| 93 | * node names they produce. |
---|
| 94 | */ |
---|
| 95 | writers: { |
---|
| 96 | "ogc": OpenLayers.Util.applyDefaults({ |
---|
| 97 | "PropertyIsEqualTo": function(filter) { |
---|
| 98 | var node = this.createElementNSPlus("ogc:PropertyIsEqualTo"); |
---|
| 99 | // no ogc:expression handling for now |
---|
| 100 | this.writeNode("PropertyName", filter, node); |
---|
| 101 | this.writeNode("Literal", filter.value, node); |
---|
| 102 | return node; |
---|
| 103 | }, |
---|
| 104 | "PropertyIsNotEqualTo": function(filter) { |
---|
| 105 | var node = this.createElementNSPlus("ogc:PropertyIsNotEqualTo"); |
---|
| 106 | // no ogc:expression handling for now |
---|
| 107 | this.writeNode("PropertyName", filter, node); |
---|
| 108 | this.writeNode("Literal", filter.value, node); |
---|
| 109 | return node; |
---|
| 110 | }, |
---|
| 111 | "PropertyIsLike": function(filter) { |
---|
| 112 | var node = this.createElementNSPlus("ogc:PropertyIsLike", { |
---|
| 113 | attributes: { |
---|
| 114 | wildCard: "*", singleChar: ".", escape: "!" |
---|
| 115 | } |
---|
| 116 | }); |
---|
| 117 | // no ogc:expression handling for now |
---|
| 118 | this.writeNode("PropertyName", filter, node); |
---|
| 119 | // convert regex string to ogc string |
---|
| 120 | this.writeNode("Literal", filter.regex2value(), node); |
---|
| 121 | return node; |
---|
| 122 | }, |
---|
| 123 | "BBOX": function(filter) { |
---|
| 124 | var node = this.createElementNSPlus("ogc:BBOX"); |
---|
| 125 | this.writeNode("PropertyName", filter, node); |
---|
| 126 | var box = this.writeNode("gml:Box", filter.value, node); |
---|
| 127 | if(filter.projection) { |
---|
| 128 | box.setAttribute("srsName", filter.projection); |
---|
| 129 | } |
---|
| 130 | return node; |
---|
| 131 | }}, OpenLayers.Format.Filter.v1.prototype.writers["ogc"]), |
---|
| 132 | |
---|
| 133 | "gml": OpenLayers.Format.GML.v2.prototype.writers["gml"], |
---|
| 134 | "feature": OpenLayers.Format.GML.v2.prototype.writers["feature"] |
---|
| 135 | |
---|
| 136 | }, |
---|
| 137 | |
---|
| 138 | /** |
---|
| 139 | * Method: writeSpatial |
---|
| 140 | * |
---|
| 141 | * Read a {<OpenLayers.Filter.Spatial>} filter and converts it into XML. |
---|
| 142 | * |
---|
| 143 | * Parameters: |
---|
| 144 | * filter - {<OpenLayers.Filter.Spatial>} The filter. |
---|
| 145 | * name - {String} Name of the generated XML element. |
---|
| 146 | * |
---|
| 147 | * Returns: |
---|
| 148 | * {DOMElement} The created XML element. |
---|
| 149 | */ |
---|
| 150 | writeSpatial: function(filter, name) { |
---|
| 151 | var node = this.createElementNSPlus("ogc:"+name); |
---|
| 152 | this.writeNode("PropertyName", filter, node); |
---|
| 153 | var child; |
---|
| 154 | if(filter.value instanceof OpenLayers.Geometry) { |
---|
| 155 | child = this.writeNode("feature:_geometry", filter.value).firstChild; |
---|
| 156 | } else { |
---|
| 157 | child = this.writeNode("gml:Box", filter.value); |
---|
| 158 | } |
---|
| 159 | if(filter.projection) { |
---|
| 160 | child.setAttribute("srsName", filter.projection); |
---|
| 161 | } |
---|
| 162 | node.appendChild(child); |
---|
| 163 | return node; |
---|
| 164 | }, |
---|
| 165 | |
---|
| 166 | |
---|
| 167 | CLASS_NAME: "OpenLayers.Format.Filter.v1_0_0" |
---|
| 168 | |
---|
| 169 | }); |
---|