diff --git a/packages/display/src/Grid.ts b/packages/display/src/Grid.ts index 4732672b..ab578468 100644 --- a/packages/display/src/Grid.ts +++ b/packages/display/src/Grid.ts @@ -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); @@ -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) { @@ -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; diff --git a/packages/display/src/displays/BasicDisplay.ts b/packages/display/src/displays/BasicDisplay.ts index 6d082aab..31cfefb5 100644 --- a/packages/display/src/displays/BasicDisplay.ts +++ b/packages/display/src/displays/BasicDisplay.ts @@ -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);