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/Filter.js
7 * @requires OpenLayers/Console.js
11 * Class: OpenLayers.Filter.Spatial
12 * This class represents a spatial filter.
13 * Currently implemented: BBOX, DWithin and Intersects
16 * - <OpenLayers.Filter>
18 OpenLayers.Filter.Spatial = OpenLayers.Class(OpenLayers.Filter, {
22 * {String} Type of spatial filter.
24 * The type should be one of:
25 * - OpenLayers.Filter.Spatial.BBOX
26 * - OpenLayers.Filter.Spatial.INTERSECTS
27 * - OpenLayers.Filter.Spatial.DWITHIN
28 * - OpenLayers.Filter.Spatial.WITHIN
29 * - OpenLayers.Filter.Spatial.CONTAINS
34 * APIProperty: property
35 * {String} Name of the context property to compare.
41 * {<OpenLayers.Bounds> || <OpenLayers.Geometry>} The bounds or geometry
42 * to be used by the filter. Use bounds for BBOX filters and geometry
43 * for INTERSECTS or DWITHIN filters.
48 * APIProperty: distance
49 * {Number} The distance to use in a DWithin spatial filter.
54 * APIProperty: distanceUnits
55 * {String} The units to use for the distance, e.g. 'm'.
60 * Constructor: OpenLayers.Filter.Spatial
61 * Creates a spatial filter.
64 * options - {Object} An optional object with properties to set on the
68 * {<OpenLayers.Filter.Spatial>}
70 initialize: function(options) {
71 OpenLayers.Filter.prototype.initialize.apply(this, [options]);
76 * Evaluates this filter for a specific feature.
79 * feature - {<OpenLayers.Feature.Vector>} feature to apply the filter to.
82 * {Boolean} The feature meets filter criteria.
84 evaluate: function(feature) {
85 var intersect = false;
87 case OpenLayers.Filter.Spatial.BBOX:
88 case OpenLayers.Filter.Spatial.INTERSECTS:
89 if(feature.geometry) {
90 var geom = this.value;
91 if(this.value.CLASS_NAME == "OpenLayers.Bounds") {
92 geom = this.value.toGeometry();
94 if(feature.geometry.intersects(geom)) {
100 OpenLayers.Console.error(
101 OpenLayers.i18n("filterEvaluateNotImplemented"));
109 * Clones this filter.
112 * {<OpenLayers.Filter.Spatial>} Clone of this filter.
115 var options = OpenLayers.Util.applyDefaults({
116 value: this.value && this.value.clone && this.value.clone()
118 return new OpenLayers.Filter.Spatial(options);
120 CLASS_NAME: "OpenLayers.Filter.Spatial"
123 OpenLayers.Filter.Spatial.BBOX = "BBOX";
124 OpenLayers.Filter.Spatial.INTERSECTS = "INTERSECTS";
125 OpenLayers.Filter.Spatial.DWITHIN = "DWITHIN";
126 OpenLayers.Filter.Spatial.WITHIN = "WITHIN";
127 OpenLayers.Filter.Spatial.CONTAINS = "CONTAINS";