Skip to content

Commit

Permalink
added(core): locally cached tiles can now be queried using [TileProvi…
Browse files Browse the repository at this point in the history
  • Loading branch information
TerminalTim committed Nov 28, 2024
1 parent 97f17fc commit 3dc78e7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/layers/cluster/ClusterTileLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class ClusterTileLayer extends TileLayer {
}

private _updateCachedTiles(bounds: GeoJSONBBox, clusterIndex: ClusterProvider, updatedTiles?: Set<Tile>) {
const tiles = clusterIndex.getCachedTilesOfBBox(bounds);
const tiles = clusterIndex.getCachedTiles(bounds);
if (tiles) {
for (let cachedTile of tiles) {
updatedTiles?.add(cachedTile);
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/providers/FeatureProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class FeatureProvider extends Provider {
if (inserted != UNDEF) {
feature = inserted;

const tiles = provider.getCachedTilesOfBBox(provider.decBBox(feature));
const tiles = provider.getCachedTiles(provider.decBBox(feature));

for (let tile of tiles) {
tile.add(<Feature>feature);
Expand Down Expand Up @@ -626,7 +626,7 @@ export class FeatureProvider extends Provider {
}

if (feature = this.getFeature((<GeoJSONFeature>feature).id)) {
const tiles = this.getCachedTilesOfBBox(this.decBBox(feature));
const tiles = this.getCachedTiles(this.decBBox(feature));

for (let tile of tiles) {
if (tile.isLoaded()) {
Expand Down Expand Up @@ -942,7 +942,7 @@ export class FeatureProvider extends Provider {
if ( // wipe all cached tiles containing provided bbox
bbox instanceof Array
) {
dataQuads = provider.getCachedTilesOfBBox(bbox, provider.level);
dataQuads = provider.getCachedTiles(bbox, provider.level);

for (let d = 0, tile; d < dataQuads.length; d++) {
tile = dataQuads[d];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/providers/ImageProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class ImageProvider extends TileProvider {
if ( // wipe all cached tiles containing provided bbox
bbox instanceof Array
) {
dataQuads = provider.getCachedTilesOfBBox(bbox, provider.level);
dataQuads = provider.getCachedTiles(bbox, provider.level);

for (let d = 0, tile; d < dataQuads.length; d++) {
tile = dataQuads[d];
Expand Down
52 changes: 23 additions & 29 deletions packages/core/src/providers/TileProvider/TileProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,30 +174,32 @@ export default abstract class TileProvider {
this.storage.forEach((tile) => tile.cbnds = null);
};


/**
* get cached tile by bounding box.
* Retrieves cached tiles within a specified bounding box or all cached tiles if no parameters are provided.
*
* If no arguments are passed, all cached tiles are returned.
* If a bounding box (`bbox`) and/or zoom level (`zoomlevel`) are provided, it filters the cached tiles based on the specified area and zoom level.
*
* @param bbox - An optional array of coordinates defining the bounding box in the format: `[minLon, minLat, maxLon, maxLat]`.
* If provided, only tiles within this geographic area will be returned.
*
* @param bbox - array of coordinates in order: [minLon, minLat, maxLon, maxLat]
* @param zoomlevel - get tiles at specified tileMargin
* @returns array of {@link Tiles}
* @param zoomlevel - An optional zoom level to filter tiles. If provided, only tiles at the specified zoom level will be returned.
*
* @returns {Tile[]} - An array of {@link Tile} objects that match the specified parameters, or all cached tiles if no parameters are given.
*/
getCachedTilesOfBBox(bbox: number[], zoomlevel?: number): Tile[] {
const minLon = bbox[0];
const minLat = bbox[1];
const maxLon = bbox[2];
const maxLat = bbox[3];
getCachedTiles(bbox?: number[], zoomlevel?: number): Tile[] {
const tiles = [];

zoomlevel = zoomlevel ^ 0;

zoomlevel ^= 0;
this.storage.forEach((tile) => {
const tBounds = tile.getContentBounds();
if (
(!zoomlevel || tile.z == zoomlevel) &&
intersectBBox(
(!bbox || intersectBBox(
tBounds[0], tBounds[2], tBounds[1], tBounds[3],
minLon, maxLon, minLat, maxLat
)
bbox[0], bbox[2], bbox[1], bbox[3]
))
) {
tiles[tiles.length] = tile;
}
Expand All @@ -206,21 +208,13 @@ export default abstract class TileProvider {
return tiles;
};

getCachedTileofQuadkey(quadkey: string, fixZoom?: number): Tile[] {
const tiles = [];
const z = quadkey.length;
this.storage.forEach((tile) => {
if (fixZoom && fixZoom != tile.z) return;
if (tile.quadkey.length >= z) {
if (tile.quadkey.indexOf(quadkey) == 0) {
tiles[tiles.length] = tile;
}
} else if (quadkey.indexOf(tile.quadkey) == 0) {
tiles[tiles.length] = tile;
}
});
return tiles;
};
/**
* @deprecated please use {@link TileProvider.getCachedTiles} instead.
* @hidden
*/
getCachedTilesOfBBox(bbox: number[], zoomlevel?: number): Tile[] {
return this.getCachedTiles(bbox, zoomlevel);
}

/**
* Set config for provider.
Expand Down
6 changes: 3 additions & 3 deletions packages/display/src/displays/FeatureModifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class FeatureModifier {
}

forEachTile(feature: Feature, cb) {
feature.getProvider().getCachedTilesOfBBox(feature.getBBox()).forEach(cb);
feature.getProvider().getCachedTiles(feature.getBBox()).forEach(cb);
}

remove(feature: Feature, tiles: Tile[], layer: TileLayer) {
Expand Down Expand Up @@ -107,8 +107,8 @@ class FeatureModifier {
layer: TileLayer
) {
let prov = layer.getProvider();
let prevTiles = prov.getCachedTilesOfBBox(prevBBox);
let curTiles = prov.getCachedTilesOfBBox(feature.getBBox());
let prevTiles = prov.getCachedTiles(prevBBox);
let curTiles = prov.getCachedTiles(feature.getBBox());

for (var t = 0, len = curTiles.length; t < len; t++) {
let iPrev = prevTiles.indexOf(curTiles[t]);
Expand Down

0 comments on commit 3dc78e7

Please sign in to comment.