New filters for extent and logical filtering

These need unit tests.
This commit is contained in:
ahocevar
2013-02-04 22:50:21 +01:00
parent 43dd9ca68c
commit 428793cd7c
2 changed files with 98 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
goog.provide('ol.filter.Extent');
goog.require('ol.Feature');
/**
* @constructor
* @implements {ol.filter.Filter}
* @param {ol.Extent} extent The extent.
*/
ol.filter.Extent = function(extent) {
/**
* @type {ol.Extent}
* @private
*/
this.extent_ = extent;
};
/**
* @return {ol.Extent} The filter extent.
*/
ol.filter.Extent.prototype.getExtent = function() {
return this.extent_;
};
/**
* @inheritDoc
*/
ol.filter.Extent.prototype.evaluate = function(feature) {
return feature.getGeometry().getBounds().intersects(this.extent_);
};

View File

@@ -0,0 +1,62 @@
goog.provide('ol.filter.Logical');
goog.provide('ol.filter.LogicalOperator');
goog.require('ol.Feature');
goog.require('ol.filter.Filter');
/**
* @constructor
* @implements {ol.filter.Filter}
* @param {Array.<ol.filter.Filter>} filters Filters to and-combine.
* @param {!ol.filter.LogicalOperator} operator Operator.
*/
ol.filter.Logical = function(filters, operator) {
/**
* @type {Array.<ol.filter.Filter>}
* @private
*/
this.filters_ = filters;
/**
* @type {!ol.filter.LogicalOperator}
*/
this.operator = operator;
};
/**
* @inheritDoc
*/
ol.filter.Logical.prototype.evaluate = function(feature) {
var filters = this.filters_,
i = 0, ii = filters.length,
operator = this.operator,
start = operator(true, false),
result = start;
while (result === start && i < ii) {
result = operator(result, filters[i].evaluate(feature));
++i;
}
return result;
};
/**
* @return {Array.<ol.filter.Filter>} The filter's filters.
*/
ol.filter.Logical.prototype.getFilters = function() {
return this.filters_;
};
/**
* @enum {!Function}
*/
ol.filter.LogicalOperator = {
AND: /** @return {boolean} result. */ function(a, b) { return a && b; },
OR: /** @return {boolean} result. */ function(a, b) { return a || b; }
};