Scale point radius based on the zoom level (point helper)
This example shows the method of adjusting the size of a point layer based on the zoom level of the map using the point layer helper. By utilizing this technique, you can easily scale the radius of the point layer by the zoom level. To replicate this example, download the earthquake sample data.
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: 6.30,
center: [-119.602, 35.732],
style: MapStyle.DATAVIZ.LIGHT
});
map.on('load', async function () {
await helpers.addPoint(map, {
data: 'YOUR_MAPTILER_DATASET_ID_HERE',
pointRadius: [
{zoom: 2, value: 1 },
{zoom: 8, value: 6 },
{zoom: 12, value: 10 },
],
pointColor: "red",
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex">
<title>Scale point radius based on the zoom level (point 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
Point layer scaled radius by property (point helper)
ExamplesScale point layer radius and color by property.