Skip to main content

MVT module · source API

TableTileLoader

Create simplified vector tiles from a table with geometry, so a browser can render a larger in-memory dataset without drawing every feature on every frame.

What it does

Use tiles as a rendering boundary, even without a tile server.

The source indexes an in-memory table, simplifies geometry for each zoom level, and serves tile-shaped results compatible with MVT workflows.

Input

A table containing geometry columns

Index

An in-browser zoom and tile index

Geometry

Clipped and simplified per zoom

Output

GeoJSON-compatible vector tile data

Detailed guide

TableTileLoader reference

The sections below cover use cases, installation, source creation, and output format.

The TableTileLoader slices a GeoJSON table into small vector tiles on the fly. This can enable rendering and interaction with a larger in-browser dataset without requiring the data to be pre-tiled or served from a tile server.

For Arrow input and consistent Arrow tile output, use the separate ArrowTableTileLoader. This source's GeoJSON behavior is unchanged.

SourceCharacteristic
File ExtensionN/A - Any table with geometries
File TypeIn-memory table
File FormatMapbox Vector Tiles
Data FormatGeoJSON table
Data sourceTableVectorTileSource

Features:

  • Visualize bigger datasets - Useful for datasets in the "mid-size" range (perhaps from 100MB-1GB), where the dataset is "small" enough to be fully loaded into the browser, but is big enough that rendering the entire dataset every frame is too slow.
  • MVTLoader compatibility* - The resulting tiles conform to the output of the MVTLoader (which loads pre-tiled tiles into GeoJSON format).
  • Geometry simplification - The geometry content in the generated tiles is cut out from the larger input GeoJSON, and optimized further to only retain the minimum level of detail appropriate for each zoom level (shapes are simplified and tiny polygons and line segments are filtered out).

Install​

npm install @loaders.gl/tiles

Or just import via a browser script tag:

<script src="https://unpkg.com/@loaders.gl/tiles/mvt/dist/dist.min.js"></script>

Usage​

import {createDataSourceSync} from '@loaders.gl/core';
import {TableTileLoader} from '@loaders.gl/tiles/mvt';
import {GeoJSONLoader} from '@loaders.gl/tables/geojson';

// Build an initial index of tiles.
const tileSource = createDataSourceSync(url, [TableTileLoader], {
core: {
loaders: [GeoJSONLoader]
}
});

// Request a particular tile.
const tile = await tileSource.getTile({z: 5, x: 10, y: 12});
const features = tile?.features || [];

Output Format​

The tiles are in geojson table format.

Options​

For shared loading controls and parser configuration, see Source options. The settings below are specific to this source.

You can fine-tune the results with an options object, although the defaults are sensible and work well for most use cases.

OptionDefaultDescription
table.coordinates'local'Set to 'wgs84' to return longitude/latitude coordinates.
table.maxZoom14Max zoom to preserve detail on; can't be higher than 24
table.generateIdundefinedWhether to generate feature ids.
table.promoteIdundefinedName of a feature property to use for feature.id.
table.tolerance3Simplification tolerance (higher means simpler)
table.indexMaxZoom5Max zoom in the initial tile index
table.maxPointsPerTile10000Max number of points per tile in the index
table.debugundefinedLogging level (0 to disable, 1 or 2)
table.lineMetricsfalseEnable line metrics tracking for LineString/MultiLineString features
table.extent4096tile extent (both width and height)
table.buffer64Tile buffer on each side
import {createDataSourceSync} from '@loaders.gl/core';
import {TableTileLoader} from '@loaders.gl/tiles/mvt';

const tileSource = createDataSourceSync(parsedGeojson, [TableTileLoader], {
table: {
coordinates: 'local',
maxZoom: 14,
tolerance: 3,
lineMetrics: false,
indexMaxZoom: 5,
maxPointsPerTile: 10000,
extent: 4096,
buffer: 64
}
});

Remarks:

  • generateId and promoteId options cannot both be specified at the same time.
  • generateId and promoteId options ignore existing id values on the feature objects.
  • By default, tiles at zoom levels above indexMaxZoom are generated on the fly, but you can pre-generate all possible tiles for data by setting indexMaxZoom and maxZoom to the same value, setting maxPointsPerTile to 0.
  • TableTileLoader only generates tiles zoom levels up to 24.

Source creation​

Create a source directly from an already parsed GeoJSON table when the application does not need core's source auto-selection:

const tileSource = TableTileLoader.createDataSourceSync(parsedGeojson, {
table: {coordinates: 'local'}
});

await tileSource.ready;

Attribution​

Includes a fork of Mapbox / Vladimir Agafonkin's geojson-vt module which is under ISC License.