Skip to content

Repository files navigation

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

varvtpbf=require('vt-pbf')varVectorTile=require('@mapbox/vector-tile').VectorTilevarProtobuf=require('pbf')vardata=fs.readFileSync(__dirname+'/fixtures/rectangle-1.0.0.pbf')vartile=newVectorTile(newProtobuf(data))varorig=tile.layers['geojsonLayer'].feature(0).toGeoJSON(0,0,1)varbuff=vtpbf(tile)fs.writeFileSync('my-tile.pbf',buff)

From geojson-vt

varvtpbf=require('vt-pbf')vargeojsonVt=require('geojson-vt')varorig=JSON.parse(fs.readFileSync(__dirname+'/fixtures/rectangle.geojson'))vartileindex=geojsonVt(orig)vartile=tileindex.getTile(1,0,0)// pass in an object mapping layername -> tile objectvarbuff=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.

About

Serialize Mapbox Vector Tiles to binary protobufs in javascript.

Resources

Code of conduct

Contributing

Security policy

Stars

206 stars

Watchers

127 watching

Forks

Releases

Packages

Used by

Contributors

Languages