1. vt-pbf
Serialize mapbox vector tiles to binary protobufs in javascript.
vt-pbf
Package: vt-pbf
Created by: mapbox
Last modified: Tue, 20 Sep 2022 17:02:33 GMT
Version: 3.1.3
License: MIT
Downloads: 4,378,493
Repository: https://github.com/mapbox/vt-pbf

Install

npm install vt-pbf
yarn add vt-pbf

vt-pbf CircleCI

Serialize Mapbox vector tiles 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 and
vector-tile-js. These both use
slightly different internal representations, so serializing each looks slightly
different:

From vector-tile-js

 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

 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.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code