Heatmap Layer
A heatmap layer renders point density as a smooth gradient. This example scatters a large cloud of points across the Paris region so the heat fills the view.
import { MaptoolkitLogoControl } from 'https://cdn.jsdelivr.net/npm/@maptoolkit/maplibre-gl-logo/+esm';
const map = new maplibregl.Map({ container: 'map', attributionControl: { customAttribution: '' }, style: 'https://styles.maptoolkit.org/summer.json', center: [2.3522, 48.8566], zoom: 9 }); // Paris region
const pts = { type: 'FeatureCollection', features: [] };
for (let i = 0; i < 1200; i++) {
pts.features.push({ type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [2.3522 + (Math.random() - 0.5) * 2.0, 48.8566 + (Math.random() - 0.5) * 1.4] } });
}
map.on('load', function () {
map.addSource('pts', { type: 'geojson', data: pts });
map.addLayer({ id: 'heat', type: 'heatmap', source: 'pts', paint: { 'heatmap-radius': 25, 'heatmap-opacity': 0.85 } });
});
map.addControl(new MaptoolkitLogoControl());<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/maplibre-gl.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/maplibre-gl.css" />
<style>
html, body { width: 100%; height: 100%; margin: 0; padding: 0; }
#map { width: 100%; height: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script type="module">
import { MaptoolkitLogoControl } from 'https://cdn.jsdelivr.net/npm/@maptoolkit/maplibre-gl-logo/+esm';
const map = new maplibregl.Map({ container: 'map', attributionControl: { customAttribution: '' }, style: 'https://styles.maptoolkit.org/summer.json', center: [2.3522, 48.8566], zoom: 9 }); // Paris region
const pts = { type: 'FeatureCollection', features: [] };
for (let i = 0; i < 1200; i++) {
pts.features.push({ type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [2.3522 + (Math.random() - 0.5) * 2.0, 48.8566 + (Math.random() - 0.5) * 1.4] } });
}
map.on('load', function () {
map.addSource('pts', { type: 'geojson', data: pts });
map.addLayer({ id: 'heat', type: 'heatmap', source: 'pts', paint: { 'heatmap-radius': 25, 'heatmap-opacity': 0.85 } });
});
map.addControl(new MaptoolkitLogoControl());
</script>
</body>
</html>