Moving the feature management to the layer
The source will be responsible for fetching vector data.
This commit is contained in:
@@ -3,112 +3,15 @@ goog.provide('ol.test.source.Vector');
|
||||
|
||||
describe('ol.source.Vector', function() {
|
||||
|
||||
var vectorSource;
|
||||
|
||||
describe('#addFeatures()', function() {
|
||||
|
||||
it('works', function() {
|
||||
vectorSource = new ol.source.Vector({
|
||||
projection: ol.projection.getFromCode('EPSG:4326')
|
||||
});
|
||||
vectorSource.addFeatures([new ol.Feature()]);
|
||||
expect(vectorSource.getFeatures().length).toEqual(1);
|
||||
describe('constructor', function() {
|
||||
it('creates an instance', function() {
|
||||
var source = new ol.source.Vector({});
|
||||
expect(source).toBeA(ol.source.Vector);
|
||||
expect(source).toBeA(ol.source.Source);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getFeatures()', function() {
|
||||
|
||||
var features;
|
||||
|
||||
beforeEach(function() {
|
||||
features = [
|
||||
new ol.Feature({
|
||||
g: new ol.geom.Point([16.0, 48.0])
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.Point([16.1, 48.1])
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.Point([16.2, 48.2])
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.Point([16.3, 48.3])
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.LineString([[16.4, 48.4], [16.5, 48.5]])
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.LineString([[16.6, 48.6], [16.7, 48.7]])
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.LineString([[16.8, 48.8], [16.9, 48.9]])
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.LineString([[17.0, 49.0], [17.1, 49.1]])
|
||||
})
|
||||
];
|
||||
vectorSource = new ol.source.Vector({
|
||||
projection: ol.projection.getFromCode('EPSG:4326')
|
||||
});
|
||||
vectorSource.addFeatures(features);
|
||||
});
|
||||
|
||||
var geomFilter = new ol.filter.Geometry(ol.geom.GeometryType.LINESTRING);
|
||||
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, 'applies');
|
||||
var lineStrings = vectorSource.getFeatures(geomFilter);
|
||||
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, 'applies');
|
||||
var subset = vectorSource.getFeatures(extentFilter);
|
||||
expect(extentFilter.applies).not.toHaveBeenCalled();
|
||||
expect(subset.length).toEqual(4);
|
||||
expect(subset).not.toContain(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);
|
||||
spyOn(filter1, 'applies');
|
||||
spyOn(filter2, 'applies');
|
||||
var subset1 = vectorSource.getFeatures(filter1);
|
||||
var subset2 = vectorSource.getFeatures(filter2);
|
||||
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 applies function', function() {
|
||||
var filter = new ol.filter.Logical([geomFilter, extentFilter],
|
||||
ol.filter.LogicalOperator.OR);
|
||||
spyOn(filter, 'applies').andCallThrough();
|
||||
var subset = vectorSource.getFeatures(filter);
|
||||
expect(filter.applies).toHaveBeenCalled();
|
||||
expect(subset.length).toEqual(8);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.Projection');
|
||||
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.geom.Point');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.source.Source');
|
||||
goog.require('ol.source.Vector');
|
||||
goog.require('ol.projection');
|
||||
|
||||
Reference in New Issue
Block a user