open-vector-tile
Version:
This library reads/writes Open Vector Tiles
41 lines • 1.37 kB
JavaScript
import wasmBase64 from './vectorTile.wasm.js';
/** Free the memory */
// type WasmFreeVectorTile = (ptr: number) => void;
/** Sentinel to allocate memory */
// type WasmAllocSentinel = (size: number) => number;
/**
* # Open Vector Tile WASM
* This is a WASM implementation of the Open Vector Tile format.
* Work in progress. Just for testing purposes currently.
*/
export class VectorTileWASM {
instance;
wasmMemory;
tmpString = '';
// #finalizationRegistry: FinalizationRegistry<number>;
/** setup */
constructor() {
const mod = new WebAssembly.Module(base64ToArrayBuffer(wasmBase64));
this.instance = new WebAssembly.Instance(mod, {
env: {},
});
// this.#finalizationRegistry = new FinalizationRegistry<number>((id: VectorTileId): void => {
// const freeS2CellId = this.instance.exports.free_s2_cell_id as WasmFreeVectorTile;
// freeS2CellId(id);
// });
}
}
/**
* polyfill
* @param base64 - the base64 string
* @returns - the array buffer of raw bytes
*/
function base64ToArrayBuffer(base64) {
const binaryString = atob(base64);
const len = binaryString.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++)
bytes[i] = binaryString.charCodeAt(i);
return bytes.buffer;
}
//# sourceMappingURL=vectorTileWASM.js.map