2.0.3 • Published 11 months ago

@mapbox/vector-tile v2.0.3

Weekly downloads
380,938
License
BSD-3-Clause
Repository
github
Last release
11 months ago

vector-tile

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

Example

import {VectorTile} from '@mapbox/vector-tile';
import Protobuf from 'pbf';

const tile = new VectorTile(new Protobuf(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);

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

import {VectorTile} from '@mapbox/vector-tile';
import Protobuf from 'pbf';
import {gunzipSync} from 'zlib';

const buffer = gunzipSync(data);
const tile = new VectorTile(new Protobuf(buffer));

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 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.)
@simosol/mapbox-gl-js-offlinebst-map-gldetlefk-leaflet.vectorgridthreerendercesiums@mapcreator/mapbox-glpddgz-tangram@datav-gi/datav-gi-jsitowns-for-meitowns-test-deployment-3itowns-test-deployment-4itowns-test-deployment-5@everything-registry/sub-chunk-579@langge-data/mapbox-gl@langge-data/vt-pbfitowns-test-deploy-with-provenanceitowns_gctangramterriajsterriajs-protomapstest-map-azsftwrx-mapbox-glsumbal-tileserver-glswsk-mapboxglthree-mapthinknetmapsthree-cesiumsvt-pbfvoluptatesidvnmapvizzuality-mapbox-glvicapow-mapbox-glvietmap-glvietmaps-gl@curio/mapbox-gl@bloc-in-bloc/itowns@rapideditor/rapiditowns-desplandis-mainitowns-geocommunsitowns-nothreadsitowns-potree2itownsgaiaitownsitowns-demo-lidarjptilesclientkarn-mapkarn-mapbox-glkepler.gl-forked-ismakutlkepler.gl.geoiqkepler.gl.sh.customkt-maplibre-gl@openmapvn/maplibre-gl@gchoqueux/itownsgeovis-map-servertruekepler.gltilequerytilefixtilebasetileserver-gltileserver-gl-lighttileserver-gl-light-customtrackasia-glthree-render-cesiumthree-render-cesium2@americana/maplibre-gl@antv/l7-source@ark-org/map@autra/giro3d@autra/itowns@autoxing/mapbox-gl@alantgeo/mapbox-gl@bagage/leaflet.vectorgrid@basemaps/lambda-tiler@bcherny/mapbox-gl@bewithjonam/mapbox-gl@carto/toolkit-viz@carto/web-sdk@carto/carto-vl@carto/kepler.gl@carto/mapbox-gl@cczbby/mapbox-gl@cczbby/maplibre-gl@cieloazul310/canvasmap-styles@cieloazul310/population-calculator@3drobotics/mapbox-gl@0xfa11/maplibre-gl@acalcutt/tileserver-gl@acalcutt/tileserver-gl-light@jupytergis/base@davidedelerma/terriajs@dfw810/mapbox-gl@datav-gi/datavgi-gl-jsxyd-mapbox-glxtal-gl@feltmaps/protomaps@felix5/mapbox-webgl2@dtcv/viewer@dterekhova/deckgl-layers@gvol-org/mapbox-gl@hansdo/maplibre-gl@golemio/vehiclesharing
2.0.3

11 months ago

2.0.2

11 months ago

2.0.1

11 months ago

2.0.0

11 months ago

1.3.1

7 years ago

1.3.0

8 years ago

1.0.0-alpha.1

9 years ago

1.0.0-rc3

9 years ago

1.0.0-rc2

9 years ago

1.0.0-rc1

9 years ago