# @maplibre/vt-pbf

> Serialize mapbox vector tiles to binary protobufs in javascript.

Latest version **4.3.2** (published 2026-06-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @maplibre/vt-pbf
pnpm add @maplibre/vt-pbf
yarn add @maplibre/vt-pbf
bun add @maplibre/vt-pbf
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.3.2 |
| Published | 2026-06-04 |
| First published | 2025-07-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 27.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 5 |
| Author | Anand Thakker |
| Maintainers | maplibreorg, wayofthefuture, harelmazor, birkskyum, mwilsnd |

## Links

- npm: https://www.npmjs.com/package/@maplibre/vt-pbf
- Repository: https://github.com/maplibre/vt-pbf
- Homepage: https://github.com/maplibre/vt-pbf#readme
- Issues: https://github.com/maplibre/vt-pbf/issues
- npm.io page: https://npm.io/package/@maplibre/vt-pbf

## Dependencies (3)

- [pbf](https://npm.io/package/pbf.md) ^5.1.0
- [@types/geojson](https://npm.io/package/@types/geojson.md) ^7946.0.16
- [@mapbox/point-geometry](https://npm.io/package/@mapbox/point-geometry.md) ^1.1.0

## Recent versions

- 4.3.2 (latest) — 2026-06-04
- 4.3.1 — 2026-06-04
- 4.3.0 — 2026-02-23
- 4.2.1 — 2026-01-22
- 4.2.0 — 2025-12-15
- 4.1.0 — 2025-11-27
- 4.0.3 — 2025-07-15
- 4.0.2 — 2025-07-14

## README

[![MapLibre Logo](https://maplibre.org/img/maplibre-logo-big.svg)](https://maplibre.org/)

# vt-pbf 
[![NPM Version](https://img.shields.io/npm/v/@maplibre/vt-pbf.svg)](https://www.npmjs.com/package/@maplibre/vt-pbf)

Serialize [Mapbox vector tiles](https://github.com/mapbox/vector-tile-spec) to binary protobufs in javascript.

## Installation
Using NPM: `npm install @maplibre/vt-pbf`

Or `npm run build` and find build artifacts in `dist/`

## Usage

As far as I know, the two places you might get a JS representation of a vector
tile are [geojson-vt](https://github.com/mapbox/geojson-vt) and
[vector-tile-js](https://github.com/mapbox/vector-tile-js).  These both use
slightly different internal representations, so serializing each looks slightly
different:

## From vector-tile-js

```javascript
import {fromVectorTileJs} from 'vt-pbf'
import {VectorTile} = from '@mapbox/vector-tile'
import Protobuf from 'pbf'

var data = fs.readFileSync(__dirname + '/fixtures/rectangle-1.0.0.pbf')
var tile = new VectorTile(new Protobuf(data))
var orig = tile.layers['geojsonLayer'].feature(0).toGeoJSON(0, 0, 1)

var buff = fromVectorTileJs(tile)
fs.writeFileSync('my-tile.pbf', buff)
```

## From geojson-vt

```javascript
import {fromGeojsonVt} from 'vt-pbf'
import geojsonVt from '@maplibre/geojson-vt'

var orig = JSON.parse(fs.readFileSync(__dirname + '/fixtures/rectangle.geojson'))
var tileindex = geojsonVt(orig)
var tile = tileindex.getTile(1, 0, 0)

// pass in an object mapping layername -> tile object
var buff = fromGeojsonVt({ 'geojsonLayer': tile })
fs.writeFileSync('my-tile.pbf', buff)
```

`fromGeojsonVt` takes two arguments:
- `layerMap` is an object where keys are layer names and values are a geojson-vt tile,
- `options` is an object (optional argument). There are 2 supported keys: `version` to define the version of the mvt spec used and `extent` to define the extent of the tile. `version` defaults to 1 and `extent` to 4096.

---
_Source: https://npm.io/package/@maplibre/vt-pbf · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
