1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the * full text of the license. */ /** * @requires OpenLayers/Filter.js */ /** * Class: OpenLayers.Filter.Logical * This class represents ogc:And, ogc:Or and ogc:Not rules. * * Inherits from * - <OpenLayers.Filter> */ OpenLayers.Filter.Logical = OpenLayers.Class(OpenLayers.Filter, { /** * APIProperty: filters * {Array(<OpenLayers.Filter>)} Child filters for this filter. */ filters: null, /** * APIProperty: type * {String} type of logical operator. Available types are: * - OpenLayers.Filter.Logical.AND = "&&"; * - OpenLayers.Filter.Logical.OR = "||"; * - OpenLayers.Filter.Logical.NOT = "!"; */ type: null, /** * Constructor: OpenLayers.Filter.Logical * Creates a logical filter (And, Or, Not). * * Parameters: * options - {Object} An optional object with properties to set on the * filter. * * Returns: * {<OpenLayers.Filter.Logical>} */ initialize: function(options) { this.filters = []; OpenLayers.Filter.prototype.initialize.apply(this, [options]); }, /** * APIMethod: destroy * Remove reference to child filters. */ destroy: function() { this.filters = null; OpenLayers.Filter.prototype.destroy.apply(this); }, /** * APIMethod: evaluate * Evaluates this filter in a specific context. Should be implemented by * subclasses. * * Parameters: * context - {Object} Context to use in evaluating the filter. * * Returns: * {Boolean} The filter applies. */ evaluate: function(context) { switch(this.type) { case OpenLayers.Filter.Logical.AND: for (var i=0, len=this.filters.length; i<len; i++) { if (this.filters[i].evaluate(context) == false) { return false; } } return true; case OpenLayers.Filter.Logical.OR: for (var i=0, len=this.filters.length; i<len; i++) { if (this.filters[i].evaluate(context) == true) { return true; } } return false; case OpenLayers.Filter.Logical.NOT: return (!this.filters[0].evaluate(context)); } }, /** * APIMethod: clone * Clones this filter. * * Returns: * {<OpenLayers.Filter.Logical>} Clone of this filter. */ clone: function() { var filters = []; for(var i=0, len=this.filters.length; i<len; ++i) { filters.push(this.filters[i].clone()); } return new OpenLayers.Filter.Logical({ type: this.type, filters: filters }); }, CLASS_NAME: "OpenLayers.Filter.Logical" }); OpenLayers.Filter.Logical.AND = "&&"; OpenLayers.Filter.Logical.OR = "||"; OpenLayers.Filter.Logical.NOT = "!"; |