@allmaps/render
Version:
Render functions for WebGL and image buffers
57 lines (56 loc) • 1.6 kB
JavaScript
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.fetchableTile.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, {
tileUrl: this.fetchableTile.tileUrl
})
);
} catch (err) {
if (err instanceof Error && err.name === "AbortError") ;
else {
this.dispatchEvent(
new WarpedMapEvent(WarpedMapEventType.TILEFETCHERROR, {
tileUrl: this.fetchableTile.tileUrl
})
);
}
}
return this.data;
}
async applySprites() {
return;
}
spritesDataToCachedTiles() {
return [];
}
static createFactory(getImageData) {
return (fetchableTile, fetchFn) => new CacheableIntArrayTile(fetchableTile, getImageData, fetchFn);
}
}
export {
CacheableIntArrayTile
};
//# sourceMappingURL=CacheableIntArrayTile.js.map