~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/lib/OpenLayers/Filter/Spatial.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

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