@expofp/floorplan
Version:
Interactive floor plan library for expos and events
53 lines • 2.7 kB
TypeScript
import { type Protocol, type RangeResponse, type Source } from 'pmtiles';
/**
* A PMTiles source that also works against hosts which accept a `Range` header
* and then answer `200` with something other than the requested slice.
*
* The Android SDK serves offline archives through `WebViewAssetLoader`, whose
* path handlers never see request headers: Chromium applies the range's start
* offset to the file stream and then streams to EOF, answering `200` with a
* `Content-Length` that merely echoes the request. PMTiles' own guard compares
* that header against the requested length and so lets it through — every tile
* read then silently receives the rest of the archive instead of one tile,
* which decodes into a mostly blank basemap and no error anywhere.
*
* So probe once, at offset 0, and decide from the status:
*
* - `206` — a well-behaved host. Everything is delegated to {@link FetchSource},
* which keeps its 416 retry and ETag-mismatch handling intact.
* - `200` — the host ignored the range, which means the body it just returned
* *is* the archive from byte 0. Keep it and slice locally.
*
* The body is held as a `Blob` rather than an `ArrayBuffer` so the browser can
* back it with a temp file instead of the JS heap — an offline basemap runs to
* tens of megabytes and the SDK still has to survive older Android WebViews.
*/
export declare class RangeTolerantSource implements Source {
private readonly url;
private readonly ranged;
/** Memoised probe: the whole archive, or `null` when ranges are honoured. */
private archive;
constructor(url: string);
getKey(): string;
getBytes(offset: number, length: number, signal?: AbortSignal, etag?: string): Promise<RangeResponse>;
/**
* Read the head of the archive and work out which kind of host this is.
*
* The probe deliberately ignores the caller's `AbortSignal`. It is memoised
* for the source's lifetime, so a first tile that gets cancelled mid-flight
* must not leave every later read awaiting a rejected promise.
*/
private probe;
}
/**
* Point the protocol at {@link RangeTolerantSource} for one archive URL.
*
* Registering ahead of the first tile request is what makes this take effect:
* `Protocol` creates a plain {@link FetchSource} for any `pmtiles://` URL it
* has not already been given an instance for.
*
* Only string-URL styles are covered. An inline style object carries absolute
* URLs the SDK never resolves, so its PMTiles sources keep the stock source.
*/
export declare function registerPmtilesArchive(protocol: Protocol, url: string): void;
//# sourceMappingURL=pmtiles-range-fallback.d.ts.map