Heatmap layer radius and weight by property (heatmap helper)
This example shows how to add a heatmap layer to the map, simultaneously controlling the radius and weight based on a property using the heatmap layer helper. Download the sample data here.
Since zoomCompensation is disabled in this example, it is recommended to view the map specifically on z12.
NPM module setup
npm install --save @maptiler/sdk
import { Map, MapStyle, config, ColorRampCollection, helpers } from '@maptiler/sdk';
import '@maptiler/sdk/dist/maptiler-sdk.css';
config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const map = new Map({
container: 'map',
zoom: 12,
center: [-77.01162, 38.94189],
style: MapStyle.DATAVIZ.DARK
});
map.on('load', async function () {
await helpers.addHeatmap(map, {
data: 'schools.geojson',
property: "students",
radius: [
{propertyValue: 100, value: 15},
{propertyValue: 800, value: 50},
],
weight: [
{propertyValue: 100, value: 0.1},
{propertyValue: 800, value: 1},
],
colorRamp: ColorRampCollection.MAGMA,
zoomCompensation: false,
opacity: 0.7,
intensity: 1.2,
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex">
<title>Heatmap layer radius and weight by property (heatmap helper) | NPM example</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div id="map"></div>
<script type="module" src="./main.js"></script>
</body>
</html>
body {margin: 0; padding: 0;}
#map {position: absolute; top: 0; bottom: 0; width: 100%;}
Related examples
Heatmap layer no zoom compensation (heatmap helper)
ExamplesCreate heatmap layers without zoom-based radius compensation.