Skip to content

Commit

Permalink
Optimize adaptive tile calculation for scenarios with many layers by …
Browse files Browse the repository at this point in the history
…utilizing a tile cache.

Signed-off-by: Tim Deubler <tim.deubler@here.com>
  • Loading branch information
TerminalTim committed Jan 10, 2025
1 parent 1c23ca1 commit 8db7d84
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/display/src/Grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class GridTile implements ViewportTile {
gridY: number;

private bounds: number[][];
private resultCache: {};

constructor(tileZoomLevel: number, x: number, y: number, size: number, gridX: number, gridY: number, bounds: number[][]) {
this.quadkey = tileUtils.tileXYToQuadKey(tileZoomLevel, gridY, gridX);
Expand All @@ -54,6 +55,8 @@ export class GridTile implements ViewportTile {
this.gridX = gridX;
this.gridY = gridY;
this.bounds = bounds;

this.resultCache = {};
}

static updateTileBBox(tx1: number, ty1: number, tileSize: number) {
Expand Down Expand Up @@ -88,6 +91,13 @@ export class GridTile implements ViewportTile {
optimiseTileLevel: boolean = true,
tiles: ViewportTile[] = []
): ViewportTile[] {
const cacheKey = minTileSize<<1|Number(optimiseTileLevel);
const cache = this.resultCache;
if (cache[cacheKey]) {
return cache[cacheKey];
}
cache[cacheKey] = tiles;

let {tileZoomLevel, gridX, gridY, scaledSize: size} = this;
if (size > minTileSize) {
const displayScale = display.s;
Expand Down
4 changes: 3 additions & 1 deletion packages/display/src/displays/BasicDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ abstract class Display {
displayTile.i = ++this.ti;
screenTiles.push(gridTile);

if (!vpTiles.find((t) => t.quadkey == quadkey && t.x == gridTile.x && t.y == gridTile.y)) {
if (!vpTiles.find((t) => t.quadkey == quadkey
// At the most zoomed-out level, tiles may repeat multiple times to fully cover the screen.
&& t.x == gridTile.x && t.y == gridTile.y)) {
vpTiles.push(gridTile);
}
display.initTile(displayTile, dLayer);
Expand Down

0 comments on commit 8db7d84

Please sign in to comment.