Open Vector Tile

A Vector Tile may parse either Mapbox or OpenVector Tile Layers The input is a Uint8Array that has encoded protobuffer messages.

Types of layers include:

  • Vector data - vector points, lines, and polygons with 3D coordinates, properties, and/or m-values
  • Image data - raster data that is RGB(A) encoded
  • Grid data: data that has a max-min range, works much like an image but has floating/double precision point values for each point on the grid
const fs = from 'fs';
import { VectorTile } from 'open-vector-tile';

// assume you can read (.pbf | .mvt | .ovt)
const fixture = fs.readFileSync('./x-y-z.vector.pbf');
// Or load with bun:
const fixture = await Bun.file('./x-y-z.vector.pbf').arrayBuffer();
// load the protobuf parsing it directly
const tile = new VectorTile(fixture);

// VECTOR API:

// example layer
const { landuse } = tile.layers;

// grab the first feature
const firstFeature = landuse.feature(0);
// grab the geometry
const geometry = firstFeature.loadGeometry();
// OR specifically ask for a geometry type
const points = firstFeature.loadPoints();
const lines = firstFeature.loadLines();
const polys = firstFeature.loadPolys();

// If you want to take advantage of the pre-tessellated and indexed geometries
// and you're loading the data for a renderer, you can grab the pre-tessellated geometry
const [flatGeometry, indices] = firstFeature.loadGeometryFlat();

// IMAGE API

// example layer
const { satellite } = tile.images;
// grab the image data
const data = satellite.image(); // Uint8Array

// GRIDDED API

// example layer
const { elevation } = tile.grids;
// grab the grid data
const data = elevation.grid(); // number[]

Constructors

Constructors

  • Parameters

    • data: ArrayBuffer | Uint8Array

      the input data to parse

    • end: number = 0

      the size of the data, leave blank to parse the entire data

    Returns VectorTile