Skip to content

Commit

Permalink
Merge pull request #1337 from matkoniecz/fix/caching
Browse files Browse the repository at this point in the history
Unbreak tile caching.
  • Loading branch information
matkoniecz authored Feb 15, 2024
2 parents 3628973 + c3cd365 commit cbf6d8e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/src/tiles/rendererDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ if(!allLayersCacheSwitch) {
}

const MIN_ZOOM_FOR_RENDERING_TILES = 9
const MAX_ZOOM_FOR_RENDERING_TILES = 19

const tileCache = new TileCache(
process.env.TILECACHE_PATH,
{
tilesets: getBuildingLayerNames(),
minZoom: MIN_ZOOM_FOR_RENDERING_TILES,
maxZoom: MAX_ZOOM_FOR_RENDERING_TILES,
scales: [1, 2]
},
shouldCacheFn,
Expand All @@ -70,8 +72,11 @@ function stitchOrRenderBuildingTile(tileParams: TileParams, dataParams: any): Pr
}

function renderTile(tileParams: TileParams, dataParams: any): Promise<Tile> {
if (isOutsideExtent(tileParams, EXTENT_BBOX) || tileParams.z < MIN_ZOOM_FOR_RENDERING_TILES) {
// if tiles are on lower zoom level then producing/caching is expected
if (isOutsideExtent(tileParams, EXTENT_BBOX)
|| tileParams.z < MIN_ZOOM_FOR_RENDERING_TILES
|| tileParams.z > MAX_ZOOM_FOR_RENDERING_TILES
) {
// if tiles are outside cache zoom level then producing/caching is expected
// then we should short-circuit tile generation
// otherwise tile would be generated and not cached

Expand Down
6 changes: 6 additions & 0 deletions app/src/tiles/tileCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ interface CacheDomain {
*/
minZoom: number;

/**
* The highest zoom level to cache
*/
maxZoom: number;

/**
* An array of scale factors to cache
*/
Expand Down Expand Up @@ -132,6 +137,7 @@ class TileCache {
private shouldUseCache(tileParams: TileParams): boolean {
return this.cacheDomain.tilesets.includes(tileParams.tileset) &&
this.cacheDomain.minZoom <= tileParams.z &&
this.cacheDomain.maxZoom >= tileParams.z &&
this.cacheDomain.scales.includes(tileParams.scale) &&
(this.shouldCacheFn == undefined || this.shouldCacheFn(tileParams));
}
Expand Down

0 comments on commit cbf6d8e

Please sign in to comment.