node-mvt-encoder
A Node.js utility to encode a vector tile spec into a Mapbox vector tile.
Installation
npm install mvt-encoder
node-gdal is a dependency of this
project. It requires gdal
to be installed in your environment:
apt-get update -y && apt-get install -y libproj-dev gdal-bin
Usage
var tileEncode = ;var VectorTile = VectorTile var tileSpec = name: 'blocks' features: geometry: "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))" properties: hello: "world" ; var encoded = ;var decoded = encoded console// { blocks: VectorTileLayer {...} }
Tile specification
The tileEncode
function exported in this module takes one parameter: a "tile
spec". This was inspired by Mapzen's
mapbox-vector-tile package.
A "tile spec" is an array of "layer specs".
a "layer spec" is an object with the properties:
name
: the name of the layer (string
)features
: an array of objects with the properties:geometry
: a WKT representation of a feature geometry. Coordinates are relative to the tile, scaled in the range [0, 4096)properties
: an object with arbitrary key/values.
Notes
- Only tested for Polygon features
- Does not quantize geometry to the tile grid
- Outputs Mapbox vector tile conforming to (at best) version 1 of the spec