SDK JS
    Preparing search index...

    Decodes Esri LERC1/LERC2 raster blobs (elevation / coverage DEMs) to a single-band Float32Array raster in the browser, backed by the vendored pure-Rust turbolerc wasm.

    Integer, float, and double source rasters are all normalized to f32. v1 covers the first band of single-depth rasters (the headline DEM use case); multi-band RGB is a follow-up. The wasm runtime is a process singleton shared by all live decoders — call LercDecoder.dispose when done so its heap can be reclaimed (see resetWasm).

    import { LercDecoder } from '@bitruvius/turbo-lerc';

    const raster = await new LercDecoder().decode(bytes); // a .lerc1/.lerc2 blob
    // raster.values: Float32Array, row-major, length width*height (first band)
    // Node/Bun or cross-origin CDN: supply the wasm explicitly via wasmInit.
    const wasmBytes = await Bun.file('turbolerc_wasm_bg.wasm').arrayBuffer();
    const decoder = new LercDecoder({ wasmInit: { wasmBytes } });
    const raster = await decoder.decode(bytes);
    decoder.dispose();
    Index

    Constructors

    Methods

    Constructors

    Methods

    • Decode a LERC blob to a single-band f32 raster (+ optional validity mask).

      Parameters

      • bytes: Uint8Array

        The raw compressed LERC1/LERC2 blob (e.g. an Esri tile or an exported .lerc1/.lerc2 file).

      Returns Promise<LercRaster>

      A LercRaster: header metadata plus a row-major Float32Array of the first band (length width * height) and, when not all-valid, a one-byte-per-pixel mask. Values lie within [zMin, zMax] in the source raster's units.

      If wasm initialization fails (the configured/default .wasm cannot be fetched or instantiated; see WasmHostInit).

      If bytes is not a valid LERC blob — the underlying wasm decode rejects a bad magic/version or a corrupt/truncated payload.

      import { LercDecoder } from '@bitruvius/turbo-lerc';
      const r = await new LercDecoder().decode(bytes);
      console.log(r.width, r.height, r.zMin, r.zMax);
    • Release this decoder's claim on the wasm runtime. When the last live LercDecoder is disposed, the singleton WebAssembly.Memory is dropped so it can be GC'd (see resetWasm) — letting a main-thread terrain layer reclaim its DEM-decode heap on teardown. Terminal: do not decode() after disposing. Idempotent.

      Returns void