getFeaturesInExtent() for VectorTile source
This commit is contained in:
@@ -7,7 +7,7 @@ import VectorRenderTile from '../VectorRenderTile.js';
|
||||
import Tile from '../VectorTile.js';
|
||||
import {toSize} from '../size.js';
|
||||
import UrlTile from './UrlTile.js';
|
||||
import {getKeyZXY} from '../tilecoord.js';
|
||||
import {getKeyZXY, fromKey} from '../tilecoord.js';
|
||||
import {createXYZ, extentFromProjection, createForProjection} from '../tilegrid.js';
|
||||
import {buffer as bufferExtent, getIntersection, intersects} from '../extent.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
@@ -170,6 +170,51 @@ class VectorTile extends UrlTile {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get features whose bounding box intersects the provided extent. Only features for cached
|
||||
* tiles for the last rendered zoom level are available in the source. So this method is only
|
||||
* suitable for requesting tiles for extents that are currently rendered.
|
||||
*
|
||||
* Features are returned in random tile order and as they are included in the tiles. This means
|
||||
* they can be clipped, duplicated across tiles, and simplified to the render resolution.
|
||||
*
|
||||
* @param {import("../extent.js").Extent} extent Extent.
|
||||
* @return {Array<import("../Feature.js").FeatureLike>} Features.
|
||||
* @api
|
||||
*/
|
||||
getFeaturesInExtent(extent) {
|
||||
const features = [];
|
||||
const tileCache = this.tileCache;
|
||||
if (tileCache.getCount() === 0) {
|
||||
return features;
|
||||
}
|
||||
const z = fromKey(tileCache.peekFirstKey())[0];
|
||||
const tileGrid = this.tileGrid;
|
||||
tileCache.forEach(function(tile) {
|
||||
if (tile.tileCoord[0] !== z || tile.getState() !== TileState.LOADED) {
|
||||
return;
|
||||
}
|
||||
const sourceTiles = tile.getSourceTiles();
|
||||
for (let i = 0, ii = sourceTiles.length; i < ii; ++i) {
|
||||
const sourceTile = sourceTiles[i];
|
||||
const tileCoord = sourceTile.tileCoord;
|
||||
if (intersects(extent, tileGrid.getTileCoordExtent(tileCoord))) {
|
||||
const tileFeatures = sourceTile.getFeatures();
|
||||
if (tileFeatures) {
|
||||
for (let j = 0, jj = tileFeatures.length; j < jj; ++j) {
|
||||
const candidate = tileFeatures[j];
|
||||
const geometry = candidate.getGeometry();
|
||||
if (geometry.intersectsExtent(extent)) {
|
||||
features.push(candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return features;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {boolean} The source can have overlapping geometries.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user