Replace use of filter with expressions
The canvas vector layer still has the (API candidate) `getFeatures` method that accepts an arbitrary expression (was filter). This, and the `getFeaturesObject` method under it are only used in the tests. The rendering code that was using filters is now calling `layer.getFeaturesObjectForExtent` with an explicit extent and optional geometry type.
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
goog.provide('ol.test.filter.Extent');
|
||||
|
||||
|
||||
describe('ol.filter.Extent', function() {
|
||||
|
||||
var extent, filter;
|
||||
|
||||
beforeEach(function() {
|
||||
extent = [0, 45, 0, 90];
|
||||
filter = new ol.filter.Extent(extent);
|
||||
});
|
||||
|
||||
describe('#getExtent()', function() {
|
||||
|
||||
it('returns the configured extent', function() {
|
||||
expect(filter.getExtent()).to.be(extent);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
|
||||
it('returns true if a feature intersects, false if not', function() {
|
||||
expect(filter.applies(new ol.Feature({g: new ol.geom.Point([44, 89])})))
|
||||
.to.be(true);
|
||||
expect(filter.applies(new ol.Feature({g: new ol.geom.Point([46, 91])})))
|
||||
.to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.filter.Extent');
|
||||
goog.require('ol.geom.Point');
|
||||
@@ -1,51 +0,0 @@
|
||||
goog.provide('ol.test.filter.Geometry');
|
||||
|
||||
|
||||
describe('ol.filter.Geometry', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new filter', function() {
|
||||
var filter = new ol.filter.Geometry(ol.filter.GeometryType.POINT);
|
||||
expect(filter).to.be.a(ol.filter.Geometry);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getType()', function() {
|
||||
|
||||
it('works for point', function() {
|
||||
var filter = new ol.filter.Geometry(ol.filter.GeometryType.POINT);
|
||||
expect(filter.getType()).to.be(ol.filter.GeometryType.POINT);
|
||||
});
|
||||
|
||||
it('works for linestring', function() {
|
||||
var filter = new ol.filter.Geometry(ol.filter.GeometryType.LINESTRING);
|
||||
expect(filter.getType()).to.be(ol.filter.GeometryType.LINESTRING);
|
||||
});
|
||||
|
||||
it('works for polygon', function() {
|
||||
var filter = new ol.filter.Geometry(ol.filter.GeometryType.POLYGON);
|
||||
expect(filter.getType()).to.be(ol.filter.GeometryType.POLYGON);
|
||||
});
|
||||
|
||||
it('works for multi-point', function() {
|
||||
var filter = new ol.filter.Geometry(ol.filter.GeometryType.MULTIPOINT);
|
||||
expect(filter.getType()).to.be(ol.filter.GeometryType.MULTIPOINT);
|
||||
});
|
||||
|
||||
it('works for multi-linestring', function() {
|
||||
var filter = new ol.filter.Geometry(
|
||||
ol.filter.GeometryType.MULTILINESTRING);
|
||||
expect(filter.getType()).to.be(ol.filter.GeometryType.MULTILINESTRING);
|
||||
});
|
||||
|
||||
it('works for multi-polygon', function() {
|
||||
var filter = new ol.filter.Geometry(ol.filter.GeometryType.MULTIPOLYGON);
|
||||
expect(filter.getType()).to.be(ol.filter.GeometryType.MULTIPOLYGON);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.filter.Geometry');
|
||||
goog.require('ol.filter.GeometryType');
|
||||
@@ -1,144 +0,0 @@
|
||||
goog.provide('ol.test.filter.Logical');
|
||||
|
||||
|
||||
describe('ol.filter.Logical', function() {
|
||||
|
||||
var OR = ol.filter.LogicalOperator.OR;
|
||||
var AND = ol.filter.LogicalOperator.AND;
|
||||
var NOT = ol.filter.LogicalOperator.NOT;
|
||||
var include = new ol.filter.Filter(function() {return true;});
|
||||
var exclude = new ol.filter.Filter(function() {return false;});
|
||||
|
||||
var apple = new ol.Feature({});
|
||||
var orange = new ol.Feature({});
|
||||
var duck = new ol.Feature({});
|
||||
|
||||
var isApple = new ol.filter.Filter(function(feature) {
|
||||
return feature === apple;
|
||||
});
|
||||
var isOrange = new ol.filter.Filter(function(feature) {
|
||||
return feature === orange;
|
||||
});
|
||||
var isDuck = new ol.filter.Filter(function(feature) {
|
||||
return feature === duck;
|
||||
});
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new filter', function() {
|
||||
var filter = new ol.filter.Logical([include, exclude], OR);
|
||||
expect(filter).to.be.a(ol.filter.Logical);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#operator', function() {
|
||||
it('can be OR', function() {
|
||||
var filter = new ol.filter.Logical([include, exclude], OR);
|
||||
expect(filter.operator).to.be(OR);
|
||||
});
|
||||
|
||||
it('can be AND', function() {
|
||||
var filter = new ol.filter.Logical([include, exclude], AND);
|
||||
expect(filter.operator).to.be(AND);
|
||||
});
|
||||
|
||||
it('can be NOT', function() {
|
||||
var filter = new ol.filter.Logical([include], NOT);
|
||||
expect(filter.operator).to.be(NOT);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#applies', function() {
|
||||
|
||||
it('works for OR', function() {
|
||||
var isFruit = new ol.filter.Logical([isApple, isOrange], OR);
|
||||
|
||||
expect(isApple.applies(apple)).to.be(true);
|
||||
expect(isOrange.applies(apple)).to.be(false);
|
||||
expect(isFruit.applies(apple)).to.be(true);
|
||||
|
||||
expect(isApple.applies(duck)).to.be(false);
|
||||
expect(isOrange.applies(duck)).to.be(false);
|
||||
expect(isFruit.applies(duck)).to.be(false);
|
||||
});
|
||||
|
||||
it('works for AND', function() {
|
||||
expect(include.applies(apple)).to.be(true);
|
||||
expect(isApple.applies(apple)).to.be(true);
|
||||
expect(isDuck.applies(apple)).to.be(false);
|
||||
|
||||
var pass = new ol.filter.Logical([include, isApple], AND);
|
||||
expect(pass.applies(apple)).to.be(true);
|
||||
|
||||
var fail = new ol.filter.Logical([isApple, isDuck], AND);
|
||||
expect(fail.applies(apple)).to.be(false);
|
||||
});
|
||||
|
||||
it('works for NOT', function() {
|
||||
expect(isApple.applies(apple)).to.be(true);
|
||||
expect(isDuck.applies(apple)).to.be(false);
|
||||
expect(isDuck.applies(duck)).to.be(true);
|
||||
expect(isDuck.applies(apple)).to.be(false);
|
||||
|
||||
var notApple = new ol.filter.Logical([isApple], NOT);
|
||||
expect(notApple.applies(apple)).to.be(false);
|
||||
expect(notApple.applies(duck)).to.be(true);
|
||||
|
||||
var notDuck = new ol.filter.Logical([isDuck], NOT);
|
||||
expect(notDuck.applies(apple)).to.be(true);
|
||||
expect(notDuck.applies(duck)).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.filter.and', function() {
|
||||
it('creates the a logical AND filter', function() {
|
||||
var a = new ol.filter.Filter();
|
||||
var b = new ol.filter.Filter();
|
||||
var c = new ol.filter.Filter();
|
||||
var and = ol.filter.and(a, b, c);
|
||||
expect(and).to.be.a(ol.filter.Logical);
|
||||
expect(and.operator).to.be(ol.filter.LogicalOperator.AND);
|
||||
var filters = and.getFilters();
|
||||
expect(filters[0]).to.be(a);
|
||||
expect(filters[1]).to.be(b);
|
||||
expect(filters[2]).to.be(c);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.filter.not', function() {
|
||||
it('creates the logical compliment of another filter', function() {
|
||||
var include = new ol.filter.Filter(function() {return true;});
|
||||
var notInclude = ol.filter.not(include);
|
||||
expect(notInclude).to.be.a(ol.filter.Logical);
|
||||
expect(notInclude.applies()).to.be(false);
|
||||
|
||||
var exclude = new ol.filter.Filter(function() {return false;});
|
||||
var notExclude = ol.filter.not(exclude);
|
||||
expect(notExclude).to.be.a(ol.filter.Logical);
|
||||
expect(notExclude.applies()).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.filter.or', function() {
|
||||
it('creates the a logical OR filter', function() {
|
||||
var a = new ol.filter.Filter();
|
||||
var b = new ol.filter.Filter();
|
||||
var c = new ol.filter.Filter();
|
||||
var and = ol.filter.or(a, b, c);
|
||||
expect(and).to.be.a(ol.filter.Logical);
|
||||
expect(and.operator).to.be(ol.filter.LogicalOperator.OR);
|
||||
var filters = and.getFilters();
|
||||
expect(filters[0]).to.be(a);
|
||||
expect(filters[1]).to.be(b);
|
||||
expect(filters[2]).to.be(c);
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.filter.Filter');
|
||||
goog.require('ol.filter.Logical');
|
||||
goog.require('ol.filter.LogicalOperator');
|
||||
goog.require('ol.filter.and');
|
||||
goog.require('ol.filter.not');
|
||||
goog.require('ol.filter.or');
|
||||
@@ -50,46 +50,46 @@ describe('ol.layer.Vector', function() {
|
||||
layer.addFeatures(features);
|
||||
});
|
||||
|
||||
var geomFilter = new ol.filter.Geometry(ol.geom.GeometryType.LINESTRING);
|
||||
var extentFilter = new ol.filter.Extent([16, 16.3, 48, 48.3]);
|
||||
var geomFilter = ol.expression.parse('geometryType("linestring")');
|
||||
var extentFilter = ol.expression.parse('extent(16, 16.3, 48, 48.3)');
|
||||
|
||||
it('can filter by geometry type using its GeometryType index', function() {
|
||||
sinon.spy(geomFilter, 'applies');
|
||||
sinon.spy(geomFilter, 'evaluate');
|
||||
var lineStrings = layer.getFeatures(geomFilter);
|
||||
expect(geomFilter.applies).to.not.be.called();
|
||||
expect(geomFilter.evaluate).to.not.be.called();
|
||||
expect(lineStrings.length).to.eql(4);
|
||||
expect(lineStrings).to.contain(features[4]);
|
||||
});
|
||||
|
||||
it('can filter by extent using its RTree', function() {
|
||||
sinon.spy(extentFilter, 'applies');
|
||||
sinon.spy(extentFilter, 'evaluate');
|
||||
var subset = layer.getFeatures(extentFilter);
|
||||
expect(extentFilter.applies).to.not.be.called();
|
||||
expect(extentFilter.evaluate).to.not.be.called();
|
||||
expect(subset.length).to.eql(4);
|
||||
expect(subset).not.to.contain(features[7]);
|
||||
});
|
||||
|
||||
it('can filter by extent and geometry type using its index', function() {
|
||||
var filter1 = new ol.filter.Logical([geomFilter, extentFilter],
|
||||
ol.filter.LogicalOperator.AND);
|
||||
var filter2 = new ol.filter.Logical([extentFilter, geomFilter],
|
||||
ol.filter.LogicalOperator.AND);
|
||||
sinon.spy(filter1, 'applies');
|
||||
sinon.spy(filter2, 'applies');
|
||||
var filter1 = new ol.expression.Logical(
|
||||
ol.expression.LogicalOp.AND, geomFilter, extentFilter);
|
||||
var filter2 = new ol.expression.Logical(
|
||||
ol.expression.LogicalOp.AND, extentFilter, geomFilter);
|
||||
sinon.spy(filter1, 'evaluate');
|
||||
sinon.spy(filter2, 'evaluate');
|
||||
var subset1 = layer.getFeatures(filter1);
|
||||
var subset2 = layer.getFeatures(filter2);
|
||||
expect(filter1.applies).to.not.be.called();
|
||||
expect(filter2.applies).to.not.be.called();
|
||||
expect(filter1.evaluate).to.not.be.called();
|
||||
expect(filter2.evaluate).to.not.be.called();
|
||||
expect(subset1.length).to.eql(0);
|
||||
expect(subset2.length).to.eql(0);
|
||||
});
|
||||
|
||||
it('can handle query using the filter\'s applies function', function() {
|
||||
var filter = new ol.filter.Logical([geomFilter, extentFilter],
|
||||
ol.filter.LogicalOperator.OR);
|
||||
sinon.spy(filter, 'applies');
|
||||
it('can handle query using the filter\'s evaluate function', function() {
|
||||
var filter = new ol.expression.Logical(
|
||||
ol.expression.LogicalOp.OR, geomFilter, extentFilter);
|
||||
sinon.spy(filter, 'evaluate');
|
||||
var subset = layer.getFeatures(filter);
|
||||
expect(filter.applies).to.be.called();
|
||||
expect(filter.evaluate).to.be.called();
|
||||
expect(subset.length).to.eql(8);
|
||||
});
|
||||
|
||||
@@ -179,11 +179,8 @@ describe('ol.layer.Vector', function() {
|
||||
goog.require('goog.dispose');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expression');
|
||||
goog.require('ol.filter.Extent');
|
||||
goog.require('ol.filter.Geometry');
|
||||
goog.require('ol.filter.Logical');
|
||||
goog.require('ol.filter.LogicalOperator');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.expression.Logical');
|
||||
goog.require('ol.expression.LogicalOp');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.proj');
|
||||
|
||||
Reference in New Issue
Block a user