vector-tile-js 0,0 eslint travis-ci npm

Parses vector tiles with JavaScript

2 years after

vector-tile

build status Coverage Status

This library reads Mapbox Vector Tiles and allows access to the layers and features.

Example

var VectorTile = require('vector-tile').VectorTile;
var Protobuf = require('pbf');

var tile = new VectorTile(new Protobuf(data));

// Contains a map of all layers
tile.layers;

var landuse = tile.layers.landuse;

// Amount of features in this layer
landuse.length;

// Returns the first feature
landuse.feature(0);

Vector tiles contained in serialtiles-spec are gzip-encoded, so a complete example of parsing them with the native zlib module would be:

var VectorTile = require('vector-tile').VectorTile;
var Protobuf = require('pbf');
var zlib = require('zlib');

zlib.gunzip(data, function(err, buffer) {
    var tile = new VectorTile(new Protobuf(buffer));
});

Depends

  • Node.js v0.10.x or v0.8.x

Install

To install:

npm install vector-tile

API Reference

VectorTile

An object that parses vector tile data and makes it readable.

Constructor

  • new VectorTile(protobuf[, end]) — parses the vector tile data contained in the given Protobuf object, saving resulting layers in the created object as a layers property. Optionally accepts end index.

Properties

  • layers (Object) — an object containing parsed layers in the form of {<name>: <layer>, ...}, where each layer is a VectorTileLayer object.

VectorTileLayer

An object that contains the data for a single vector tile layer.

Properties

  • version (Number, default: 1)
  • name (String)— layer name
  • extent (Number, default: 4096) — tile extent size
  • length (Number) — number of features in the layer

Methods

  • feature(i) — get a feature (VectorTileFeature) by the given index from the layer.

VectorTileFeature

An object that contains the data for a single feature.

Properties

  • type (Number) — type of the feature (also see VectorTileFeature.types)
  • extent (Number) — feature extent size
  • id (Number) — feature identifier, if present
  • properties (Object) — object literal with feature properties

Methods

  • loadGeometry() — parses feature geometry and returns an array of Point arrays (with each point having x and y properties)
  • bbox() — calculates and returns the bounding box of the feature in the form [x1, y1, x2, y2]
  • toGeoJSON(x, y, z) — returns a GeoJSON representation of the feature. (x, y, and z refer to the containing tile's index.)

Related Repositories

vector-river-map

vector-river-map

Tutorial project demonstrating making a web map with vector tiles ...

awesome-vector-tiles

awesome-vector-tiles

awesome implementations of the Mapbox Vector Tile specification ...

carmen

carmen

Mapnik vector tile-based geocoder with support for swappable data sources ...

kartotherian

kartotherian

Wikipedia Maps Tile Server ...

vector-tile-server

vector-tile-server

Vector tile server and rendering backend for Mapnik ...


Top Contributors

mourner jfirebaugh tmcw springmeyer cschwarz nyurik anandthakker ahocevar ansis kkaefer dnomadb

Dependencies

package version
@mapbox/point-geometry ~0.1.0
dev benchmark ^1.0.0
coveralls ~2.11.2
istanbul ~0.3.6
mapnik ^3.6.0
jshint ^2.6.3
pbf ^1.3.2
tape ~3.5.0
eslint ~1.00.0
eslint-config-unstyled ^1.1.0

Releases

-   v1.3.0 zip tar
-   v1.2.1 zip tar
-   v1.2.0 zip tar
-   v1.1.3 zip tar
-   v1.1.2 zip tar
-   v1.1.1 zip tar
-   v1.1.0 zip tar
-   v1.0.0 zip tar
-   v0.1.3 zip tar
-   v0.0.5 zip tar
-   v0.0.4 zip tar
-   v0.0.3 zip tar
-   v0.0.2 zip tar
-   v0.0.1 zip tar