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/Filter.js |
---|
8 | * @requires OpenLayers/Console.js |
---|
9 | */ |
---|
10 | |
---|
11 | /** |
---|
12 | * Class: OpenLayers.Filter.Spatial |
---|
13 | * This class represents a spatial filter. |
---|
14 | * Currently implemented: BBOX, DWithin and Intersects |
---|
15 | * |
---|
16 | * Inherits from |
---|
17 | * - <OpenLayers.Filter> |
---|
18 | */ |
---|
19 | OpenLayers.Filter.Spatial = OpenLayers.Class(OpenLayers.Filter, { |
---|
20 | |
---|
21 | /** |
---|
22 | * APIProperty: type |
---|
23 | * {String} Type of spatial filter. |
---|
24 | * |
---|
25 | * The type should be one of: |
---|
26 | * - OpenLayers.Filter.Spatial.BBOX |
---|
27 | * - OpenLayers.Filter.Spatial.INTERSECTS |
---|
28 | * - OpenLayers.Filter.Spatial.DWITHIN |
---|
29 | * - OpenLayers.Filter.Spatial.WITHIN |
---|
30 | * - OpenLayers.Filter.Spatial.CONTAINS |
---|
31 | */ |
---|
32 | type: null, |
---|
33 | |
---|
34 | /** |
---|
35 | * APIProperty: property |
---|
36 | * {String} Name of the context property to compare. |
---|
37 | */ |
---|
38 | property: null, |
---|
39 | |
---|
40 | /** |
---|
41 | * APIProperty: value |
---|
42 | * {<OpenLayers.Bounds> || <OpenLayers.Geometry>} The bounds or geometry |
---|
43 | * to be used by the filter. Use bounds for BBOX filters and geometry |
---|
44 | * for INTERSECTS or DWITHIN filters. |
---|
45 | */ |
---|
46 | value: null, |
---|
47 | |
---|
48 | /** |
---|
49 | * APIProperty: distance |
---|
50 | * {Number} The distance to use in a DWithin spatial filter. |
---|
51 | */ |
---|
52 | distance: null, |
---|
53 | |
---|
54 | /** |
---|
55 | * APIProperty: distanceUnits |
---|
56 | * {String} The units to use for the distance, e.g. 'm'. |
---|
57 | */ |
---|
58 | distanceUnits: null, |
---|
59 | |
---|
60 | /** |
---|
61 | * Constructor: OpenLayers.Filter.Spatial |
---|
62 | * Creates a spatial filter. |
---|
63 | * |
---|
64 | * Parameters: |
---|
65 | * options - {Object} An optional object with properties to set on the |
---|
66 | * filter. |
---|
67 | * |
---|
68 | * Returns: |
---|
69 | * {<OpenLayers.Filter.Spatial>} |
---|
70 | */ |
---|
71 | initialize: function(options) { |
---|
72 | OpenLayers.Filter.prototype.initialize.apply(this, [options]); |
---|
73 | }, |
---|
74 | |
---|
75 | /** |
---|
76 | * Method: evaluate |
---|
77 | * Evaluates this filter for a specific feature. |
---|
78 | * |
---|
79 | * Parameters: |
---|
80 | * feature - {<OpenLayers.Feature.Vector>} feature to apply the filter to. |
---|
81 | * |
---|
82 | * Returns: |
---|
83 | * {Boolean} The feature meets filter criteria. |
---|
84 | */ |
---|
85 | evaluate: function(feature) { |
---|
86 | var intersect = false; |
---|
87 | switch(this.type) { |
---|
88 | case OpenLayers.Filter.Spatial.BBOX: |
---|
89 | case OpenLayers.Filter.Spatial.INTERSECTS: |
---|
90 | if(feature.geometry) { |
---|
91 | var geom = this.value; |
---|
92 | if(this.value.CLASS_NAME == "OpenLayers.Bounds") { |
---|
93 | geom = this.value.toGeometry(); |
---|
94 | } |
---|
95 | if(feature.geometry.intersects(geom)) { |
---|
96 | intersect = true; |
---|
97 | } |
---|
98 | } |
---|
99 | break; |
---|
100 | default: |
---|
101 | OpenLayers.Console.error( |
---|
102 | OpenLayers.i18n("filterEvaluateNotImplemented")); |
---|
103 | break; |
---|
104 | } |
---|
105 | return intersect; |
---|
106 | }, |
---|
107 | |
---|
108 | /** |
---|
109 | * APIMethod: clone |
---|
110 | * Clones this filter. |
---|
111 | * |
---|
112 | * Returns: |
---|
113 | * {<OpenLayers.Filter.Spatial>} Clone of this filter. |
---|
114 | */ |
---|
115 | clone: function() { |
---|
116 | var options = OpenLayers.Util.applyDefaults({ |
---|
117 | value: this.value && this.value.clone && this.value.clone() |
---|
118 | }, this); |
---|
119 | return new OpenLayers.Filter.Spatial(options); |
---|
120 | }, |
---|
121 | CLASS_NAME: "OpenLayers.Filter.Spatial" |
---|
122 | }); |
---|
123 | |
---|
124 | OpenLayers.Filter.Spatial.BBOX = "BBOX"; |
---|
125 | OpenLayers.Filter.Spatial.INTERSECTS = "INTERSECTS"; |
---|
126 | OpenLayers.Filter.Spatial.DWITHIN = "DWITHIN"; |
---|
127 | OpenLayers.Filter.Spatial.WITHIN = "WITHIN"; |
---|
128 | OpenLayers.Filter.Spatial.CONTAINS = "CONTAINS"; |
---|