# vt-pbf

> Serialize mapbox vector tiles to binary protobufs in javascript.

Latest version **3.1.3** (published 2021-06-07) · MIT license · 2.5M weekly downloads

## Install

```sh
npm install vt-pbf
pnpm add vt-pbf
yarn add vt-pbf
bun add vt-pbf
```

## Health

**Score 53/100 (C)** — status: abandoned.

Positive: high downloads; has types package; no vulnerabilities; high quality score.

Warnings: no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.1.3 |
| Published | 2021-06-07 |
| First published | 2015-07-22 |
| Weekly downloads | 2.5M |
| License | MIT |
| TypeScript types | separate (@types/vt-pbf) |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 11.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 206 |
| Author | Anand Thakker |
| Maintainers | lxbarth, miccolis, mourner, mcwhittemore, ianshward, gretacb, ansis, morganherlocker, jfirebaugh, samanbb, nickidlugash, ian29, dnomadb, lbud, bsudekum, sgillies, rclark, tristen, 1ec5, karenzshea, anandthakker, ingalls, lyzidiamond, jrpruit1, freenerd, ajashton, flippmoke, bergwerkgis, themarex, sbma44, emilymcafee, planemad, bhousel, mtirwin, alulsh, mapbox-admin |

## Links

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

## Dependencies (3)

- [pbf](https://npm.io/package/pbf.md) ^3.2.1
- [@mapbox/vector-tile](https://npm.io/package/@mapbox/vector-tile.md) ^1.3.1
- [@mapbox/point-geometry](https://npm.io/package/@mapbox/point-geometry.md) 0.1.0

## Recent versions

- 3.1.3 (latest) — 2021-06-07
- 3.1.2 — 2021-05-19
- 3.1.1 — 2018-05-15
- 3.1.0 — 2017-11-01
- 3.0.1 — 2017-09-06
- 2.1.4 — 2017-08-01
- 3.0.0 — 2017-08-01
- 2.1.3 — 2017-07-24
- 2.1.2 — 2016-08-16
- 2.1.1 — 2016-08-15
- 2.1.0 — 2016-08-15
- 2.0.2 — 2015-10-15
- 2.0.1 — 2015-09-15
- 2.0.0 — 2015-07-24
- 1.0.2 — 2015-07-23
- … 2 more at https://npm.io/package/vt-pbf/versions

## README

# vt-pbf [![CircleCI](https://circleci.com/gh/mapbox/vt-pbf.svg?style=svg)](https://circleci.com/gh/mapbox/vt-pbf)

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

## 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
var vtpbf = require('vt-pbf')
var VectorTile = require('@mapbox/vector-tile').VectorTile
var Protobuf = require('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 = vtpbf(tile)
fs.writeFileSync('my-tile.pbf', buff)
```

## From geojson-vt

```javascript
var vtpbf = require('vt-pbf')
var geojsonVt = require('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 = vtpbf.fromGeojsonVt({ 'geojsonLayer': tile })
fs.writeFileSync('my-tile.pbf', buff)
```

`vtpbf.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/vt-pbf · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
