Parses vector tiles with JavaScript
  • JavaScript 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-03 22:24:13 +02:00
.github/workflows upgrade CI to Node v24 (LTS) 2026-05-25 14:37:44 +03:00
proto initial commit 2014-04-12 18:15:36 -04:00
test upgrade to pbf v5.0.0 2026-05-26 19:20:41 +03:00
.gitignore test 2026-10-03 22:24:13 +02:00
bench.js modernize (ESM, modern deps, GitHub Actions) 2024-07-10 22:58:17 +03:00
CODEOWNERS Add CODEOWNERS file (#94) 2026-06-18 11:25:47 +03:00
eslint.config.js add first-class TypeScript types 2024-07-11 12:14:43 +03:00
index.d.ts test 2026-10-03 22:24:13 +02:00
index.js feat: implement Symbol.iterator in VectorTileLayer class 2026-10-03 22:18:59 +02:00
LICENSE.txt modernize (ESM, modern deps, GitHub Actions) 2024-07-10 22:58:17 +03:00
package-lock.json 3.0.0 2026-05-26 19:21:25 +03:00
package.json 3.0.0 2026-05-26 19:21:25 +03:00
README.md update readme 2026-05-27 00:30:05 +03:00
tsconfig.json add first-class TypeScript types 2024-07-11 12:14:43 +03:00

vector-tile

This library reads Mapbox Vector Tiles and allows access to the layers and features. Depends on pbf v5+.

Example

import {VectorTile} from '@mapbox/vector-tile';
import {PbfReader} from 'pbf';

const tile = new VectorTile(new PbfReader(data));

// Contains a map of all layers
tile.layers;

const landuse = tile.layers.landuse;

// Amount of features in this layer
landuse.length;

// Returns the first feature
landuse.feature(0);

Vector tiles contained in serialtiles-spec are gzip-encoded, so a complete example of parsing them with the native zlib module would be:

import {VectorTile} from '@mapbox/vector-tile';
import {PbfReader} from 'pbf';
import {gunzipSync} from 'zlib';

const buffer = gunzipSync(data);
const tile = new VectorTile(new PbfReader(buffer));

Install

To install:

npm install @mapbox/vector-tile

API Reference

VectorTile

An object that parses vector tile data and makes it readable.

Constructor

  • new VectorTile(pbf[, end]) — parses the vector tile data contained in the given PbfReader object, saving resulting layers in the created object as a layers property. Optionally accepts end index.

Properties

  • layers (Object) — an object containing parsed layers in the form of {<name>: <layer>, ...}, where each layer is a VectorTileLayer object.

VectorTileLayer

An object that contains the data for a single vector tile layer.

Properties

  • version (Number, default: 1)
  • name (String) — layer name
  • extent (Number, default: 4096) — tile extent size
  • length (Number) — number of features in the layer

Methods

  • feature(i) — get a feature (VectorTileFeature) by the given index from the layer.

VectorTileFeature

An object that contains the data for a single feature.

Properties

  • type (Number) — type of the feature (also see VectorTileFeature.types)
  • extent (Number) — feature extent size
  • id (Number) — feature identifier, if present
  • properties (Object) — object literal with feature properties

Methods

  • loadGeometry() — parses feature geometry and returns an array of Point arrays (with each point having x and y properties)
  • bbox() — calculates and returns the bounding box of the feature in the form [x1, y1, x2, y2]
  • toGeoJSON(x, y, z) — returns a GeoJSON representation of the feature. (x, y, and z refer to the containing tile's index.)