Project

General

Profile

Download (3.34 KB) Statistics
| Branch: | Tag: | Revision:
1
/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
2
 * full list of contributors). Published under the 2-clause BSD license.
3
 * See license.txt in the OpenLayers distribution or repository for the
4
 * full text of the license. */
5

    
6

    
7
/**
8
 * @requires OpenLayers/Filter.js
9
 */
10

    
11
/**
12
 * Class: OpenLayers.Filter.Logical
13
 * This class represents ogc:And, ogc:Or and ogc:Not rules.
14
 * 
15
 * Inherits from:
16
 * - <OpenLayers.Filter>
17
 */
18
OpenLayers.Filter.Logical = OpenLayers.Class(OpenLayers.Filter, {
19

    
20
    /**
21
     * APIProperty: filters
22
     * {Array(<OpenLayers.Filter>)} Child filters for this filter.
23
     */
24
    filters: null, 
25
     
26
    /**
27
     * APIProperty: type
28
     * {String} type of logical operator. Available types are:
29
     * - OpenLayers.Filter.Logical.AND = "&&";
30
     * - OpenLayers.Filter.Logical.OR  = "||";
31
     * - OpenLayers.Filter.Logical.NOT = "!";
32
     */
33
    type: null,
34

    
35
    /** 
36
     * Constructor: OpenLayers.Filter.Logical
37
     * Creates a logical filter (And, Or, Not).
38
     *
39
     * Parameters:
40
     * options - {Object} An optional object with properties to set on the
41
     *     filter.
42
     * 
43
     * Returns:
44
     * {<OpenLayers.Filter.Logical>}
45
     */
46
    initialize: function(options) {
47
        this.filters = [];
48
        OpenLayers.Filter.prototype.initialize.apply(this, [options]);
49
    },
50
    
51
    /** 
52
     * APIMethod: destroy
53
     * Remove reference to child filters.
54
     */
55
    destroy: function() {
56
        this.filters = null;
57
        OpenLayers.Filter.prototype.destroy.apply(this);
58
    },
59

    
60
    /**
61
     * APIMethod: evaluate
62
     * Evaluates this filter in a specific context.
63
     * 
64
     * Parameters:
65
     * context - {Object} Context to use in evaluating the filter.  A vector
66
     *     feature may also be provided to evaluate feature attributes in 
67
     *     comparison filters or geometries in spatial filters.
68
     * 
69
     * Returns:
70
     * {Boolean} The filter applies.
71
     */
72
    evaluate: function(context) {
73
        var i, len;
74
        switch(this.type) {
75
            case OpenLayers.Filter.Logical.AND:
76
                for (i=0, len=this.filters.length; i<len; i++) {
77
                    if (this.filters[i].evaluate(context) == false) {
78
                        return false;
79
                    }
80
                }
81
                return true;
82
                
83
            case OpenLayers.Filter.Logical.OR:
84
                for (i=0, len=this.filters.length; i<len; i++) {
85
                    if (this.filters[i].evaluate(context) == true) {
86
                        return true;
87
                    }
88
                }
89
                return false;
90
            
91
            case OpenLayers.Filter.Logical.NOT:
92
                return (!this.filters[0].evaluate(context));
93
        }
94
        return undefined;
95
    },
96
    
97
    /**
98
     * APIMethod: clone
99
     * Clones this filter.
100
     * 
101
     * Returns:
102
     * {<OpenLayers.Filter.Logical>} Clone of this filter.
103
     */
104
    clone: function() {
105
        var filters = [];        
106
        for(var i=0, len=this.filters.length; i<len; ++i) {
107
            filters.push(this.filters[i].clone());
108
        }
109
        return new OpenLayers.Filter.Logical({
110
            type: this.type,
111
            filters: filters
112
        });
113
    },
114
    
115
    CLASS_NAME: "OpenLayers.Filter.Logical"
116
});
117

    
118

    
119
OpenLayers.Filter.Logical.AND = "&&";
120
OpenLayers.Filter.Logical.OR  = "||";
121
OpenLayers.Filter.Logical.NOT = "!";
(4-4/5)