diff --git a/js/v3.ts b/js/v3.ts index e10b708..577055e 100644 --- a/js/v3.ts +++ b/js/v3.ts @@ -238,7 +238,7 @@ export class FileAPISource implements Source { async getBytes( offset: number, - length: number, + length: number ): Promise<[ArrayBuffer, undefined]> { const blob = this.file.slice(offset, offset + length); const a = await blob.arrayBuffer(); @@ -471,7 +471,8 @@ export class Cache { resolve(directory); if (this.cache.has(cacheKey)) { - this.cache.get(cacheKey)!.size = ENTRY_SIZE_BYTES * directory.length; + this.cache.get(cacheKey)!.size = + ENTRY_SIZE_BYTES * directory.length; this.sizeBytes += ENTRY_SIZE_BYTES * directory.length; } this.prune(); @@ -528,6 +529,10 @@ export class PMTiles { const tile_id = zxyToTileId(z, x, y); const header = await this.cache.getHeader(this.source); + if (z < header.minzoom || z > header.maxzoom) { + return undefined; + } + let d_o = header.rootDirectoryOffset; let d_l = header.rootDirectoryLength; for (let depth = 0; depth < 5; depth++) {