Add an uploaded vector tileset in MapLibre GL JS
Add an uploaded vector tileset to MapLibre GL JS as a vector source from its TileJSON URL, so bounds and zoom come from metadata. Includes JS and React.
Overview
This guide adds an uploaded vector tileset in MapLibre GL JS through the tileset TileJSON URL.
If your tileset starts as an MBTiles or PMTiles file, upload it through the console first. See Upload Data for the full upload workflow, then copy the tileset ID from the Tileset ID column and get an API key from API Keys & Access.
This example uses mappinest.COUNTIES, a public sample uploaded vector tileset. It loads the TileJSON URL as a vector source so MapLibre GL JS can read the tile template, bounds, and zoom range from one endpoint.
To load your own data, replace mappinest.COUNTIES with your tileset ID from the Tileset ID column in the console under Data → Tilesets. Use the source layer returned by the TileJSON vector_layers array when you add the map layer.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Mappinest vector TileJSON with MapLibre GL JS</title>
<link href="https://unpkg.com/maplibre-gl@5/dist/maplibre-gl.css" rel="stylesheet" />
<style>
body { margin: 0; }
#map { height: 100vh; width: 100vw; }
</style>
</head>
<body>
<div id="map"></div>
<script src="https://unpkg.com/maplibre-gl@5/dist/maplibre-gl.js"></script>
<script>
const apiKey = 'YOUR_MAPPINEST_KEY';
// Set this to the TileJSON vector_layers[].id for the layer you want to render.
const SOURCE_LAYER = 'COUNTIES';
const map = new maplibregl.Map({
container: 'map',
style: `https://api.mappinest.com/v1/maps/light/style.json?key=${apiKey}`,
center: [-98.5795, 39.8283],
zoom: 3.6
});
map.addControl(new maplibregl.NavigationControl(), 'top-right');
map.on('load', () => {
// TileJSON lets MapLibre GL JS discover the tile URL, bounds, and zoom range.
map.addSource('mappinest-counties', {
type: 'vector',
url: `https://api.mappinest.com/v1/tiles/mappinest.COUNTIES.json?key=${apiKey}`
});
map.addLayer({
id: 'counties-fill',
type: 'fill',
source: 'mappinest-counties',
'source-layer': SOURCE_LAYER,
paint: {
'fill-color': '#2563eb',
'fill-opacity': 0.28
}
});
map.addLayer({
id: 'counties-line',
type: 'line',
source: 'mappinest-counties',
'source-layer': SOURCE_LAYER,
paint: {
'line-color': '#1d4ed8',
'line-width': 1
}
});
});
</script>
</body>
</html>import { useEffect, useRef } from 'react';
import maplibregl from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';
const apiKey = 'YOUR_MAPPINEST_KEY';
// Set this to the TileJSON vector_layers[].id for the layer you want to render.
const SOURCE_LAYER = 'COUNTIES';
export default function MappinestMapLibreVectorTilesMap() {
const containerRef = useRef<HTMLDivElement | null>(null);
const mapRef = useRef<maplibregl.Map | null>(null);
useEffect(() => {
if (!containerRef.current || mapRef.current) return;
const map = new maplibregl.Map({
container: containerRef.current,
style: `https://api.mappinest.com/v1/maps/light/style.json?key=${apiKey}`,
center: [-98.5795, 39.8283],
zoom: 3.6
});
mapRef.current = map;
map.on('load', () => {
// TileJSON lets MapLibre GL JS discover the tile URL, bounds, and zoom range.
map.addSource('mappinest-counties', {
type: 'vector',
url: `https://api.mappinest.com/v1/tiles/mappinest.COUNTIES.json?key=${apiKey}`
});
map.addLayer({
id: 'counties-fill',
type: 'fill',
source: 'mappinest-counties',
'source-layer': SOURCE_LAYER,
paint: {
'fill-color': '#2563eb',
'fill-opacity': 0.28
}
});
map.addLayer({
id: 'counties-line',
type: 'line',
source: 'mappinest-counties',
'source-layer': SOURCE_LAYER,
paint: {
'line-color': '#1d4ed8',
'line-width': 1
}
});
});
return () => {
map.remove();
mapRef.current = null;
};
}, []);
return <div ref={containerRef} style={{ height: 420, width: '100%' }} />;
}URL patterns used in this example
The bold parameters are the values you replace. Prefer TileJSON as the integration request so the tile template, bounds, zoom range, and vector layer metadata stay behind one URL.
Get your free API key in API Keys & Access, then replace YOUR_KEY in the example.
Common errors
What to read next
Last updated: October 24, 2026