New filters for extent and logical filtering
These need unit tests.
This commit is contained in:
36
src/ol/filter/extentfilter.js
Normal file
36
src/ol/filter/extentfilter.js
Normal 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_);
|
||||
};
|
||||
62
src/ol/filter/logicalfilter.js
Normal file
62
src/ol/filter/logicalfilter.js
Normal 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; }
|
||||
};
|
||||
Reference in New Issue
Block a user