67.2 GB
208,150 files
Updated about 2 months ago
Ctrl+K
| Name | Size | Uploaded | Xet hash |
|---|---|---|---|
| lib | 3 items | ||
| proto | 1 items | ||
| test | 18 items | ||
| .eslintrc | 41 Bytes xet | 8f0d29c1 | |
| .travis.yml | 82 Bytes xet | 21d86a86 | |
| CHANGELOG.md | 947 Bytes xet | 5fb8292e | |
| LICENSE.txt | 1.5 kB xet | 72b4bead | |
| README.md | 3.04 kB xet | a2728347 | |
| fixtures.js | 4.4 kB xet | 9544358a | |
| index.js | 204 Bytes xet | ad764987 | |
| package.json | 865 Bytes xet | 2f3b906d |
vector-tile
This library reads Mapbox Vector Tiles and allows access to the layers and features.
Example
var VectorTile = require('@mapbox/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 @mapbox/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
layersproperty. Optionally accepts end index.
Properties
- layers (Object) — an object containing parsed layers in the form of
{<name>: <layer>, ...}, where each layer is aVectorTileLayerobject.
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 seeVectorTileFeature.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
xandyproperties) - 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, andzrefer to the containing tile's index.)
- Total size
- 67.2 GB
- Files
- 208,150
- Last updated
- Sep 27
- Pre-warmed CDN
- US EU US EU