Heatmap layer weight (heatmap helper)
This example shows how to add a heatmap layer into a map by utilizing a property as the weight. To accomplish this, the heatmap layer helper is employed. If you wish to access the earthquake sample data.
Incorporating a property as the weight MUST be paired with a ramping description. By configuring these options, earthquakes with magnitudes close to zero will be displayed with reduced intensity, while earthquakes with magnitudes of 6 or higher will be portrayed at their maximum intensity.
NPM module setup
npm install --save @maptiler/sdk
import { Map, MapStyle, config, 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: 10.82,
center: [-112.5033, 46.8634],
style: MapStyle.DATAVIZ.LIGHT
});
map.on('load', async function () {
await helpers.addHeatmap(map, {
data: 'YOUR_MAPTILER_DATASET_ID_HERE',
property: "mag", // use the earthquake magnitude to add weight to each point
weight: [
{propertyValue: 0, value: 0},
{propertyValue: 6, value: 1},
],
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex">
<title>Heatmap layer weight (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 custom radius (heatmap helper)
ExamplesImplement custom zoom-ramping radius in heatmap layers.