getFeaturesInExtent() for VectorTile source
This commit is contained in:
@@ -13,6 +13,8 @@ import {listen, unlistenByKey} from '../../../../src/ol/events.js';
|
||||
import TileState from '../../../../src/ol/TileState.js';
|
||||
import {getCenter} from '../../../../src/ol/extent.js';
|
||||
import {unByKey} from '../../../../src/ol/Observable.js';
|
||||
import Feature from '../../../../src/ol/Feature.js';
|
||||
import {fromExtent} from '../../../../src/ol/geom/Polygon.js';
|
||||
|
||||
describe('ol.source.VectorTile', function() {
|
||||
|
||||
@@ -354,4 +356,68 @@ describe('ol.source.VectorTile', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('getFeatuersInExtent', function() {
|
||||
|
||||
let map, source, target;
|
||||
|
||||
beforeEach(function() {
|
||||
source = new VectorTileSource({
|
||||
maxZoom: 15,
|
||||
tileSize: 256,
|
||||
url: '{z}/{x}/{y}',
|
||||
tileLoadFunction: function(tile) {
|
||||
const extent = source.getTileGrid().getTileCoordExtent(tile.tileCoord);
|
||||
const feature = new Feature(fromExtent(extent));
|
||||
feature.set('z', tile.tileCoord[0]);
|
||||
tile.setFeatures([feature]);
|
||||
}
|
||||
});
|
||||
target = document.createElement('div');
|
||||
target.style.width = '100px';
|
||||
target.style.height = '100px';
|
||||
document.body.appendChild(target);
|
||||
map = new Map({
|
||||
target: target,
|
||||
layers: [
|
||||
new VectorTileLayer({
|
||||
source: source
|
||||
})
|
||||
],
|
||||
view: new View({
|
||||
center: [0, 0],
|
||||
zoom: 0
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
map.setTarget(null);
|
||||
document.body.removeChild(target);
|
||||
});
|
||||
|
||||
it('returns an empty array when no tiles are in the cache', function() {
|
||||
source.tileCache.clear();
|
||||
const extent = map.getView().calculateExtent(map.getSize());
|
||||
expect(source.getFeaturesInExtent(extent).length).to.be(0);
|
||||
});
|
||||
|
||||
it('returns features in extent for the last rendered z', function(done) {
|
||||
map.getView().setZoom(15);
|
||||
map.once('rendercomplete', function() {
|
||||
const extent = map.getView().calculateExtent(map.getSize());
|
||||
const features = source.getFeaturesInExtent(extent);
|
||||
expect(features.length).to.be(4);
|
||||
expect(features[0].get('z')).to.be(15);
|
||||
map.getView().setZoom(0);
|
||||
map.once('rendercomplete', function() {
|
||||
const extent = map.getView().calculateExtent(map.getSize());
|
||||
const features = source.getFeaturesInExtent(extent);
|
||||
expect(features.length).to.be(1);
|
||||
expect(features[0].get('z')).to.be(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user