Skip to main content

MVT loader

Turn one vector tile into usable features.

MVTLoader decodes protobuf tile layers into Arrow tables by default, with explicit GeoJSON and binary shapes for mapping workflows.

What the loader does

Decode the payload. Choose the coordinate space.

The tile address is supplied by the application or source. The loader focuses on decoding layers, geometry commands, properties, and the requested output representation.

Input

A protobuf-encoded MVT payload

Geometry

Tile-local or WGS84 coordinates

Properties

Feature attributes from each layer

Output

Arrow table by default, or explicit GeoJSON/binary shapes

From-v1.0

Loader for the Mapbox Vector Tile format for representation of geometry.

Detailed guide

Loader options and output shapes

The detailed reference below covers recognition, usage, coordinate conversion, and the output structures returned by MVTLoader.

MVTLoader
File Extension.mvt,
File TypeBinary
File FormatMapbox Vector Tile
Data FormatGeometry
Data sourceMVTTileSource
Supported APIsload, parse, parseSync

Usage​

import {MVTLoader} from '@loaders.gl/tiles/mvt';
import {load} from '@loaders.gl/core';

// Arrow table containing local coordinates decoded from tile origin.
const geometryData = await load(url, MVTLoader);

// Array containing GeoJSON Features
const loaderOptions = {
mvt: {
coordinates: 'wgs84',
shape: 'geojson-table',
tileIndex: {
x: 0,
y: 0,
z: 0
}
}
};

const geoJSONfeatures = await load(url, MVTLoader, loaderOptions);

Outputs​

GeoJSON​

Set mvt.shape to 'geojson-table' to return an array of GeoJSON objects with WGS84 coordinates and feature properties from MVT. coordinates: 'wgs84' requires a matching tileIndex.

import {MVTLoader} from '@loaders.gl/tiles/mvt';
import {load} from '@loaders.gl/core';

const geoJSONfeatures = await load(url, MVTLoader, {
mvt: {
coordinates: 'wgs84',
shape: 'geojson-table',
tileIndex: {
x: xTileIndex,
y: yTileIndex,
z: zTileIndex
}
}
});

GeoJSON with local coordinates​

The parser returns an Arrow table with local coordinates by default. Set mvt.shape to 'geojson-table' for an array of GeoJSON objects.

Even though tile coordinates go from 0 to 1, there can be some negative (or greater than one) coordinates because of buffer cells within MVT to handle geometry clipping. That difference can be as much as bufferSize / tileExtent depending on MVT creation parameters.

Note that local coordinates are relative to tile origin, which is in the top left.

import {MVTLoader} from '@loaders.gl/tiles/mvt';
import {load} from '@loaders.gl/core';

const geoJSONfeatures = await load(url, MVTLoader, {mvt: {shape: 'geojson-table'}});

/*
* Default loader options are:
*
* {
* mvt: {
* coordinates: 'local',
* shape: 'arrow'
* }
* }
*/

Options​

OptionTypeDefaultDescription
mvt.shape'geojson-table' | 'columnar-table' | 'binary-geometry' | 'arrow'arrowReturned tile shape. Use geojson-table for feature objects or binary-geometry for binary geometry output.
mvt.coordinates'local' | 'wgs84'localwgs84: returns coordinates in longitude, latitude using the provided tile index. local returns local 0-1 coordinates relative to the tile origin.
mvt.tileIndex{x: number, y: number, z: number}N/AWhen the wgs84 coordinates option, the index of the tile being loaded (x, y, z) must be supplied.
mvt.layerPropertystring | null'layerName'When non-null, the layer name of each feature is added to feature.properties[layerProperty]. If null, a layer name property will not be added.
mvt.layersstring[]N/AIf provided, only features belonging to the named layers will be included, otherwise features from all layers are returned.

If you want to know more about how geometries are encoded into MVT tiles, please read this documentation section.

For GeoJSON output, mvt.sourceLayer: true adds the original vector-tile layer name to feature.sourceLayer, a GeoJSON foreign member outside feature.properties. It defaults to false. Combine it with mvt.layerProperty: null to preserve all authored properties, including properties named layerName or sourceLayer. This option does not add provenance to Arrow, columnar or binary output.

Attribution​

The MVTLoader is a fork of @mapbox/vector-tile module under the BSD-3-Clause.