mvt-reader

A library for decoding and reading mapbox vector tiles in Rust and WebAssembly

10 releases (6 stable)

1.5.0 Jul 21, 2024
1.4.0 Jun 4, 2024
1.2.0 Oct 26, 2023
1.1.0 Jun 20, 2023
1.0.0-alpha.3 May 29, 2023

#120 in Geospatial

Download history 158/week @ 2024-07-20 75/week @ 2024-07-27 4/week @ 2024-08-03 39/week @ 2024-08-10 35/week @ 2024-08-17 6/week @ 2024-08-24 3/week @ 2024-08-31 1/week @ 2024-09-07 16/week @ 2024-09-14 42/week @ 2024-09-21 33/week @ 2024-09-28 125/week @ 2024-10-05 63/week @ 2024-10-12 54/week @ 2024-10-19 59/week @ 2024-10-26 15/week @ 2024-11-02

224 downloads per month

MIT license

30KB
436 lines

mvt-reader

Mapbox vector tile reader in Rust
A library for decoding and reading mapbox vector tiles in Rust and WebAssembly

Features

  • Decodes and reads Mapbox vector tiles in Rust
  • Provides an API for accessing layer names and features within a vector tile
  • Can be used as a WebAssembly module in JavaScript (enabled by the wasm feature)

Build the project

cargo build --release

Run tests

cargo test
wasm-pack build --release --target nodejs -d pkg/node -- --features wasm && npm test

Usage

To use the mvt-reader library in your Rust project, add the following to your Cargo.toml file:

[dependencies]
mvt-reader = "1.5.0"

Then, you can import and use the library in your code:

use mvt_reader::{Reader, ParserError};

fn main() -> Result<(), ParserError> {
  // Read a vector tile from file or data
  let data = vec![/* Vector tile data */];
  let reader = Reader::new(data)?;

  // Get layer names
  let layer_names = reader.get_layer_names()?;
  for name in layer_names {
    println!("Layer: {}", name);
  }

  // Get features for a specific layer
  let layer_index = 0;
  let features = reader.get_features(layer_index)?;
  for feature in features {
    todo!()
  }

  Ok(())
}

WebAssembly Usage

To use the mvt-reader library as a WebAssembly module in JavaScript, you can install it with npm and use it in your JavaScript code:

const { Reader } = require('mvt-reader')
const fs = require('fs')

// Example usage
const reader = new Reader(fs.readFileSync('path/to/tile.mvt'))
const layerNames = reader.getLayerNames()
console.log(layerNames)

// More code...

License

This project is licensed under the MIT License.

Dependencies

~1–3.5MB
~56K SLoC