Add an uploaded raster tileset in MapLibre GL JS
Add an uploaded raster tileset to MapLibre GL JS as a raster source from its TileJSON URL. Copy the JavaScript and React examples and check common errors.
Overview
This guide shows how to add an uploaded raster tileset in MapLibre GL JS through TileJSON.
If your tileset starts as an MBTiles, PMTiles, or GeoTIFF 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.
The example uses mappinest.countries-raster, a public sample uploaded raster tileset. It loads the TileJSON URL as a raster source so MapLibre GL JS can discover the tile URL and zoom metadata from one endpoint.
To load your own data, replace mappinest.countries-raster with your tileset ID from the Tileset ID column in the console under Data → Tilesets.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Mappinest raster 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';
const map = new maplibregl.Map({
container: 'map',
style: `https://api.mappinest.com/v1/maps/light/style.json?key=${apiKey}`,
center: [0, 0],
zoom: 1
});
map.addControl(new maplibregl.NavigationControl(), 'top-right');
map.on('load', () => {
// TileJSON lets MapLibre GL JS discover the raster tile URL and zoom range.
map.addSource('countries-raster', {
type: 'raster',
url: `https://api.mappinest.com/v1/tiles/mappinest.countries-raster.json?key=${apiKey}`,
tileSize: 256
});
map.addLayer({
id: 'countries-raster-layer',
type: 'raster',
source: 'countries-raster',
paint: {
'raster-opacity': 0.9
}
});
});
</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';
export default function MappinestMapLibreRasterTilesMap() {
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: [0, 0],
zoom: 1
});
mapRef.current = map;
map.on('load', () => {
// TileJSON lets MapLibre GL JS discover the raster tile URL and zoom range.
map.addSource('countries-raster', {
type: 'raster',
url: `https://api.mappinest.com/v1/tiles/mappinest.countries-raster.json?key=${apiKey}`,
tileSize: 256
});
map.addLayer({
id: 'countries-raster-layer',
type: 'raster',
source: 'countries-raster',
paint: {
'raster-opacity': 0.9
}
});
});
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 raster tile template and zoom 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: November 3, 2026