GithubHelp home page GithubHelp logo

isabella232 / vt-pbf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mapbox/vt-pbf

0.0 0.0 0.0 857 KB

Serialize Mapbox Vector Tiles to binary protobufs in javascript.

License: Other

JavaScript 100.00%

vt-pbf's Introduction

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.

vt-pbf's People

Contributors

anandthakker avatar andrewharvey avatar hannesj avatar jfirebaugh avatar joshhardy avatar mourner avatar trysound avatar tyrasd avatar vicb avatar wsw0108 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.