UNPKG

@allmaps/render

Version:

Render functions for WebGL and image buffers

47 lines (46 loc) 1.4 kB
import { fetchUrl } from "@allmaps/stdlib"; import { CacheableTile } from "./CacheableTile.js"; import { WarpedMapEvent, WarpedMapEventType } from "../shared/events.js"; class CacheableIntArrayTile extends CacheableTile { getImageData; constructor(fetchableTile, getImageData, fetchFn) { super(fetchableTile, fetchFn); this.getImageData = getImageData; } /** * Fetch the tile and create its IntArray data using the supplied getImageData function. * * @returns */ async fetch() { try { const response = await fetchUrl( this.tileUrl, { signal: this.abortController.signal }, this.fetchFn ); const arrayBuffer = await response.arrayBuffer(); this.data = this.getImageData(new Uint8ClampedArray(arrayBuffer)); this.dispatchEvent( new WarpedMapEvent(WarpedMapEventType.TILEFETCHED, this.tileUrl) ); } catch (err) { if (err instanceof Error && err.name === "AbortError") ; else { this.dispatchEvent( new WarpedMapEvent(WarpedMapEventType.TILEFETCHERROR, this.tileUrl) ); } } return this.data; } static createFactory(getImageData) { return (fetchableTile, fetchFn) => new CacheableIntArrayTile(fetchableTile, getImageData, fetchFn); } } export { CacheableIntArrayTile }; //# sourceMappingURL=CacheableIntArrayTile.js.map