mlt-wasm 0.1.12

WebAssembly bindings for the MapLibre Tile (MLT) format
Documentation

mlt-wasm

WebAssembly bindings for the MapLibre Tile (MLT) decoder.

Compiles mlt-core to WASM via wasm-bindgen and ships a TypeScript wrapper exposing a VectorTileLike API.

Layout

mlt-wasm/
├── src/lib.rs         # wasm-bindgen bindings
├── js/
│   ├── index.ts       # package entry point
│   └── vectorTile.ts  # VectorTileLike wrapper
├── pkg/               # wasm-pack output (gitignored)
├── dist/              # tsc output (gitignored)
├── Cargo.toml
├── package.json
└── tsconfig.json

Build

Requires wasm-pack and Node.js.

npm run build

This runs wasm-pack build --target bundler --out-dir pkg followed by tsc. Both steps are also available individually:

npm run build:wasm
npm run build:ts

Usage

import { decodeTile } from '@maplibre/mlt-wasm';

const data = new Uint8Array(await fetch(tileUrl).then(r => r.arrayBuffer()));
const tile = decodeTile(data);

for (const [name, layer] of Object.entries(tile.layers)) {
    for (let i = 0; i < layer.length; i++) {
        const feature = layer.feature(i);
        console.log(feature.type);           // 1 | 2 | 3
        console.log(feature.id);             // number | undefined
        console.log(feature.properties);     // fetched lazily from WASM
        console.log(feature.loadGeometry()); // Point[][]
    }
}