[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 | /** |
---|
| 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 | switch(this.type) { |
---|
| 74 | case OpenLayers.Filter.Logical.AND: |
---|
| 75 | for (var i=0, len=this.filters.length; i<len; i++) { |
---|
| 76 | if (this.filters[i].evaluate(context) == false) { |
---|
| 77 | return false; |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | return true; |
---|
| 81 | |
---|
| 82 | case OpenLayers.Filter.Logical.OR: |
---|
| 83 | for (var i=0, len=this.filters.length; i<len; i++) { |
---|
| 84 | if (this.filters[i].evaluate(context) == true) { |
---|
| 85 | return true; |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | return false; |
---|
| 89 | |
---|
| 90 | case OpenLayers.Filter.Logical.NOT: |
---|
| 91 | return (!this.filters[0].evaluate(context)); |
---|
| 92 | } |
---|
| 93 | }, |
---|
| 94 | |
---|
| 95 | /** |
---|
| 96 | * APIMethod: clone |
---|
| 97 | * Clones this filter. |
---|
| 98 | * |
---|
| 99 | * Returns: |
---|
| 100 | * {<OpenLayers.Filter.Logical>} Clone of this filter. |
---|
| 101 | */ |
---|
| 102 | clone: function() { |
---|
| 103 | var filters = []; |
---|
| 104 | for(var i=0, len=this.filters.length; i<len; ++i) { |
---|
| 105 | filters.push(this.filters[i].clone()); |
---|
| 106 | } |
---|
| 107 | return new OpenLayers.Filter.Logical({ |
---|
| 108 | type: this.type, |
---|
| 109 | filters: filters |
---|
| 110 | }); |
---|
| 111 | }, |
---|
| 112 | |
---|
| 113 | CLASS_NAME: "OpenLayers.Filter.Logical" |
---|
| 114 | }); |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | OpenLayers.Filter.Logical.AND = "&&"; |
---|
| 118 | OpenLayers.Filter.Logical.OR = "||"; |
---|
| 119 | OpenLayers.Filter.Logical.NOT = "!"; |
---|