Tiles and Large Spatial Datasets
🎯 Introduction
By the end of this article, you will be able to explain why loading millions of GeoJSON records at once is impractical and organize large datasets by map viewport using TileLayer or MVTLayer.
🧱 Why avoid loading millions of GeoJSON records at once?
Loading all GeoJSON at once increases network transfer, parsing, memory use, and GPU attribute computation. Users see only a local area, so the browser has no need to process the entire world's data first.
Tiles divide space into small pieces, and the map requests only those needed near the current viewport. As the zoom level changes, it loads the newly required spatial coverage.
🧩 How TileLayer works
TileLayer manages tile indexing, loading, and caching. It typically passes each tile to renderSubLayers, which turns it into an actual deck.gl sublayer:
const layer = new TileLayer({
id: 'district-tiles',
data: 'https://example.com/tiles/{z}/{x}/{y}.json',
tileSize: 512,
renderSubLayers: (props) => new PolygonLayer({
...props,
getPolygon: (item) => item.polygon,
getFillColor: [37, 99, 235, 100],
}),
});
overlay.setProps({ layers: [layer] });
The Mapbox basemap still provides roads and place names, while TileLayer loads application data tiles on demand.
🗺 MVTLayer and vector tiles
MVTLayer reads Mapbox Vector Tile data: binary vector data organized into tiles:
const layer = new MVTLayer({
id: 'large-vector-data',
data: 'https://example.com/data/{z}/{x}/{y}.pbf',
getFillColor: [14, 165, 233, 100],
getLineColor: [2, 132, 199, 220],
getLineWidth: 2,
});
overlay.setProps({ layers: [layer] });
Mapbox Vector Tile and MVTLayer are different concepts. The former is a data format and tiling scheme; the latter is the deck.gl layer that reads and renders it. Mapbox can also read vector tiles and apply styles. deck.gl is better suited to data-driven GPU styling and interaction for application features within those tiles.
🔄 Tile lifecycle
Tiles typically go through loading, display, caching, and removal. As the viewport changes, TileLayer checks which tiles remain visible and reuses loaded results. Production projects also need to handle failed loads, request cancellation, and data simplification at different zoom levels.
The Mapbox basemap can be combined with a preview of TileLayer data tiles. Replace the layer with MVTLayer as needed:
⚖️ GeoJSON, TileLayer, and MVTLayer
- Small extent and manageable record count: use GeoJSON with ordinary deck.gl layers directly.
- Large extent requiring tiled loading: use TileLayer to manage the tile lifecycle.
- Server already provides MVT: use MVTLayer to read vector tiles.
- Mapbox Vector Tile describes a map data transfer format; MVTLayer provides deck.gl rendering capabilities for that data.
🧾 Summary
- Tiles let the browser process only data near the viewport.
- TileLayer manages tile indexing, loading, and caching.
- MVTLayer turns vector tiles into deck.gl graphics.
- Mapbox basemaps provide geographic context; deck.gl tile layers visualize application data.
❓ Questions and answers
Q1: Are TileLayer and MVTLayer alternatives?
Not exactly. TileLayer is a general tile manager; MVTLayer specializes in reading MVT vector tiles.
Q2: Why not merge all tiles into one GeoJSON dataset?
That loses the benefit of viewport-based loading and brings back the cost of transferring and parsing a large dataset all at once.
Q3: If Mapbox can display MVT, why use deck.gl?
Mapbox excels at styling and map layer management, while deck.gl excels at data-driven GPU graphics, aggregation, picking, and animation. Choose based on your application's visualization goals.
🧪 Exercises
- Change
tileSizefrom512to256and consider how tile counts and request coverage might change. - Add
pickable: truetoMVTLayerand design a details tooltip for vector tile features.
🎉 You now know how to load large spatial datasets onto the page tile by tile as the map viewport changes.
