vicb / vector-tile

Read mapbox vector tiles

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vector-tile

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

It is based on @mapbox/vector-tile with the following differences:

  • this library does not depend on @mapbox/point-geometry,
  • this library uses protobuf-ts to decode protos,
  • this library is written in TypeScript,
  • this library provides Feature.asPoint(), Feature.asLine(), Feature.asPolygon() to make it easier to work with geometries.

Install

npm i --save mapbox-vector-tile

Example

import { VectorTile } from 'mapbox-vector-tile';

// data is either a Buffer or a Uint8Array containing binary data.
const tile = new VectorTile(data);

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

const landuse = tile.layers.landuse;

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

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

Notes

  • 64-bit numbers could be returned as number (the default), string or bigint. You can specify the format using the second parameter of VectorTile.
  • The features id are always returned as a numerical string.

Changes

0.3.0 - Oct 22, 2020

About

Read mapbox vector tiles

License:MIT License


Languages

Language:TypeScript 94.2%Language:JavaScript 5.8%