Renaming the 'evaluate' method to 'applies'
This commit is contained in:
@@ -32,6 +32,6 @@ ol.filter.Extent.prototype.getExtent = function() {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.filter.Extent.prototype.evaluate = function(feature) {
|
||||
ol.filter.Extent.prototype.applies = function(feature) {
|
||||
return feature.getGeometry().getBounds().intersects(this.extent_);
|
||||
};
|
||||
|
||||
@@ -14,4 +14,4 @@ ol.filter.Filter = function() {};
|
||||
* @param {ol.Feature} feature Feature to evaluate.
|
||||
* @return {boolean} The provided feature passes this filter.
|
||||
*/
|
||||
ol.filter.Filter.prototype.evaluate = function(feature) {};
|
||||
ol.filter.Filter.prototype.applies = function(feature) {};
|
||||
|
||||
@@ -25,7 +25,7 @@ ol.filter.Geometry = function(type) {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.filter.Geometry.prototype.evaluate = function(feature) {
|
||||
ol.filter.Geometry.prototype.applies = function(feature) {
|
||||
var geometry = feature.getGeometry();
|
||||
return goog.isNull(geometry) ? false : geometry.getType() === this.type_;
|
||||
};
|
||||
|
||||
@@ -30,14 +30,14 @@ ol.filter.Logical = function(filters, operator) {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.filter.Logical.prototype.evaluate = function(feature) {
|
||||
ol.filter.Logical.prototype.applies = 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));
|
||||
result = operator(result, filters[i].applies(feature));
|
||||
++i;
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -128,7 +128,7 @@ ol.source.FeatureCache.prototype.getFeaturesObject_ = function(opt_filter) {
|
||||
features = {};
|
||||
for (i in candidates) {
|
||||
feature = candidates[i];
|
||||
if (opt_filter.evaluate(feature) === true) {
|
||||
if (opt_filter.applies(feature) === true) {
|
||||
features[i] = feature;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ describe('ol.filter.Extent', function() {
|
||||
describe('#evaluate()', function() {
|
||||
|
||||
it('returns true if a feature intersects, false if not', function() {
|
||||
expect(filter.evaluate(new ol.Feature({g: new ol.geom.Point([44, 89])})))
|
||||
expect(filter.applies(new ol.Feature({g: new ol.geom.Point([44, 89])})))
|
||||
.toBe(true);
|
||||
expect(filter.evaluate(new ol.Feature({g: new ol.geom.Point([46, 91])})))
|
||||
expect(filter.applies(new ol.Feature({g: new ol.geom.Point([46, 91])})))
|
||||
.toBe(false);
|
||||
});
|
||||
|
||||
|
||||
@@ -57,17 +57,17 @@ describe('ol.source.Vector', function() {
|
||||
var extentFilter = new ol.filter.Extent(new ol.Extent(16, 48, 16.3, 48.3));
|
||||
|
||||
it('can filter by geometry type using its GeometryType index', function() {
|
||||
spyOn(geomFilter, 'evaluate');
|
||||
spyOn(geomFilter, 'applies');
|
||||
var lineStrings = vectorSource.getFeatures(geomFilter);
|
||||
expect(geomFilter.evaluate).not.toHaveBeenCalled();
|
||||
expect(geomFilter.applies).not.toHaveBeenCalled();
|
||||
expect(lineStrings.length).toEqual(4);
|
||||
expect(lineStrings).toContain(features[4]);
|
||||
});
|
||||
|
||||
it('can filter by extent using its RTree', function() {
|
||||
spyOn(extentFilter, 'evaluate');
|
||||
spyOn(extentFilter, 'applies');
|
||||
var subset = vectorSource.getFeatures(extentFilter);
|
||||
expect(extentFilter.evaluate).not.toHaveBeenCalled();
|
||||
expect(extentFilter.applies).not.toHaveBeenCalled();
|
||||
expect(subset.length).toEqual(4);
|
||||
expect(subset).not.toContain(features[7]);
|
||||
});
|
||||
@@ -77,22 +77,22 @@ describe('ol.source.Vector', function() {
|
||||
ol.filter.LogicalOperator.AND);
|
||||
var filter2 = new ol.filter.Logical([extentFilter, geomFilter],
|
||||
ol.filter.LogicalOperator.AND);
|
||||
spyOn(filter1, 'evaluate');
|
||||
spyOn(filter2, 'evaluate');
|
||||
spyOn(filter1, 'applies');
|
||||
spyOn(filter2, 'applies');
|
||||
var subset1 = vectorSource.getFeatures(filter1);
|
||||
var subset2 = vectorSource.getFeatures(filter2);
|
||||
expect(filter1.evaluate).not.toHaveBeenCalled();
|
||||
expect(filter2.evaluate).not.toHaveBeenCalled();
|
||||
expect(filter1.applies).not.toHaveBeenCalled();
|
||||
expect(filter2.applies).not.toHaveBeenCalled();
|
||||
expect(subset1.length).toEqual(0);
|
||||
expect(subset2.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('can handle query using the filter\'s evaluate function', function() {
|
||||
it('can handle query using the filter\'s applies function', function() {
|
||||
var filter = new ol.filter.Logical([geomFilter, extentFilter],
|
||||
ol.filter.LogicalOperator.OR);
|
||||
spyOn(filter, 'evaluate').andCallThrough();
|
||||
spyOn(filter, 'applies').andCallThrough();
|
||||
var subset = vectorSource.getFeatures(filter);
|
||||
expect(filter.evaluate).toHaveBeenCalled();
|
||||
expect(filter.applies).toHaveBeenCalled();
|
||||
expect(subset.length).toEqual(8);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user