Heatmap layer custom color ramp (heatmap helper)
This example illustrates the process of incorporating a heatmap layer into the map by utilizing the heatmap layer helper. With the assistance of the helper, it becomes feasible to introduce a personalized color ramp. In the given example, we define a customized WARM color scheme, instead of the default TURBO option. To replicate this example, download the earthquake sample data.
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: 6.56,
center: [-119.715, 37.999],
style: MapStyle.DATAVIZ.DARK
});
map.on('load', async function () {
await helpers.addHeatmap(map, {
data: 'YOUR_MAPTILER_DATASET_ID_HERE',
colorRamp: ColorRampCollection.WARM,
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex">
<title>Heatmap layer custom color ramp (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%;}