Making consistent the evaluate method of filters. The evaluate method accepts vector features, making possible logical filters that combine spatial and comparison filters. r=ahocevar (closes #2773)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10596 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2010-08-05 15:38:55 +00:00
parent c15a1a0779
commit e0c3db1227
6 changed files with 215 additions and 23 deletions
+2 -1
View File
@@ -42,7 +42,8 @@ OpenLayers.Filter = OpenLayers.Class({
* subclasses.
*
* Parameters:
* context - {Object} Context to use in evaluating the filter.
* context - {Object} Context to use in evaluating the filter. If a vector
* feature is provided, the feature.attributes will be used as context.
*
* Returns:
* {Boolean} The filter applies.
+14 -12
View File
@@ -93,20 +93,23 @@ OpenLayers.Filter.Comparison = OpenLayers.Class(OpenLayers.Filter, {
/**
* APIMethod: evaluate
* Evaluates this filter in a specific context. Should be implemented by
* subclasses.
* Evaluates this filter in a specific context.
*
* Parameters:
* context - {Object} Context to use in evaluating the filter.
* context - {Object} Context to use in evaluating the filter. If a vector
* feature is provided, the feature.attributes will be used as context.
*
* Returns:
* {Boolean} The filter applies.
*/
evaluate: function(context) {
if (context instanceof OpenLayers.Feature.Vector) {
context = context.attributes;
}
var result = false;
var got = context[this.property];
switch(this.type) {
case OpenLayers.Filter.Comparison.EQUAL_TO:
var got = context[this.property];
var exp = this.value;
if(!this.matchCase &&
typeof got == "string" && typeof exp == "string") {
@@ -116,7 +119,6 @@ OpenLayers.Filter.Comparison = OpenLayers.Class(OpenLayers.Filter, {
}
break;
case OpenLayers.Filter.Comparison.NOT_EQUAL_TO:
var got = context[this.property];
var exp = this.value;
if(!this.matchCase &&
typeof got == "string" && typeof exp == "string") {
@@ -126,24 +128,24 @@ OpenLayers.Filter.Comparison = OpenLayers.Class(OpenLayers.Filter, {
}
break;
case OpenLayers.Filter.Comparison.LESS_THAN:
result = context[this.property] < this.value;
result = got < this.value;
break;
case OpenLayers.Filter.Comparison.GREATER_THAN:
result = context[this.property] > this.value;
result = got > this.value;
break;
case OpenLayers.Filter.Comparison.LESS_THAN_OR_EQUAL_TO:
result = context[this.property] <= this.value;
result = got <= this.value;
break;
case OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO:
result = context[this.property] >= this.value;
result = got >= this.value;
break;
case OpenLayers.Filter.Comparison.BETWEEN:
result = (context[this.property] >= this.lowerBoundary) &&
(context[this.property] <= this.upperBoundary);
result = (got >= this.lowerBoundary) &&
(got <= this.upperBoundary);
break;
case OpenLayers.Filter.Comparison.LIKE:
var regexp = new RegExp(this.value, "gi");
result = regexp.test(context[this.property]);
result = regexp.test(got);
break;
}
return result;
+4 -3
View File
@@ -58,11 +58,12 @@ OpenLayers.Filter.Logical = OpenLayers.Class(OpenLayers.Filter, {
/**
* APIMethod: evaluate
* Evaluates this filter in a specific context. Should be implemented by
* subclasses.
* Evaluates this filter in a specific context.
*
* Parameters:
* context - {Object} Context to use in evaluating the filter.
* context - {Object} Context to use in evaluating the filter. A vector
* feature may also be provided to evaluate feature attributes in
* comparison filters or geometries in spatial filters.
*
* Returns:
* {Boolean} The filter applies.