mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 10:51:07 +00:00
js v2 compatibility shim supports tile cancellation
This commit is contained in:
@@ -81,15 +81,16 @@ export class Protocol {
|
|||||||
controller.abort();
|
controller.abort();
|
||||||
};
|
};
|
||||||
|
|
||||||
instance.getZxy(+z, +x, +y, signal).then((arr) => {
|
instance.getZxy(+z, +x, +y, signal).then((resp) => {
|
||||||
if (arr) {
|
if (resp) {
|
||||||
let data = new Uint8Array(arr.data);
|
callback(null, new Uint8Array(resp.data), resp.cacheControl, resp.expires);
|
||||||
callback(null, data, null, null);
|
|
||||||
} else {
|
} else {
|
||||||
callback(null, new Uint8Array(), null, null);
|
callback(null, new Uint8Array(), null, null);
|
||||||
}
|
}
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.log(e);
|
if (e.name !== "AbortError") {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
cancel: cancel
|
cancel: cancel
|
||||||
|
|||||||
@@ -780,7 +780,7 @@ export class PMTiles {
|
|||||||
|
|
||||||
// V2 COMPATIBILITY
|
// V2 COMPATIBILITY
|
||||||
if (header.specVersion < 3) {
|
if (header.specVersion < 3) {
|
||||||
return v2.getZxy(header, this.source, this.cache, z, x, y);
|
return v2.getZxy(header, this.source, this.cache, z, x, y, signal);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (z < header.minZoom || z > header.maxZoom) {
|
if (z < header.minZoom || z > header.maxZoom) {
|
||||||
|
|||||||
7
js/v2.ts
7
js/v2.ts
@@ -261,7 +261,8 @@ async function getZxy(
|
|||||||
cache: Cache,
|
cache: Cache,
|
||||||
z: number,
|
z: number,
|
||||||
x: number,
|
x: number,
|
||||||
y: number
|
y: number,
|
||||||
|
signal?: AbortSignal
|
||||||
): Promise<RangeResponse | undefined> {
|
): Promise<RangeResponse | undefined> {
|
||||||
let root_dir = await cache.getArrayBuffer(
|
let root_dir = await cache.getArrayBuffer(
|
||||||
source,
|
source,
|
||||||
@@ -275,7 +276,7 @@ async function getZxy(
|
|||||||
|
|
||||||
const entry = queryTile(new DataView(root_dir), z, x, y);
|
const entry = queryTile(new DataView(root_dir), z, x, y);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
let resp = await source.getBytes(entry.offset, entry.length); // TODO signal
|
let resp = await source.getBytes(entry.offset, entry.length, signal);
|
||||||
let tile_data = resp.data;
|
let tile_data = resp.data;
|
||||||
|
|
||||||
let view = new DataView(tile_data);
|
let view = new DataView(tile_data);
|
||||||
@@ -309,7 +310,7 @@ async function getZxy(
|
|||||||
}
|
}
|
||||||
let tile_entry = queryTile(new DataView(leaf_dir), z, x, y);
|
let tile_entry = queryTile(new DataView(leaf_dir), z, x, y);
|
||||||
if (tile_entry) {
|
if (tile_entry) {
|
||||||
let resp = await source.getBytes(tile_entry.offset, tile_entry.length); // TODO signal
|
let resp = await source.getBytes(tile_entry.offset, tile_entry.length, signal);
|
||||||
let tile_data = resp.data;
|
let tile_data = resp.data;
|
||||||
|
|
||||||
let view = new DataView(tile_data);
|
let view = new DataView(tile_data);
|
||||||
|
|||||||
Reference in New Issue
Block a user