Point layer colored and sized according to a property (point helper)
This example illustrates the process of incorporating a point layer into a map, with the color and size of the points determined by the “mag” property, which represents the magnitude of earthquakes. To achieve this, we utilize the point layer helper. To access the sample data necessary for this exercise, please download the earthquake sample data.
In this particular case, we have opted to establish magnitude boundaries ranging between 1 and 5.
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: 4.30,
center: [-167.99, 52.7],
style: MapStyle.DATAVIZ.LIGHT
});
map.on('load', async function () {
await helpers.addPoint(map, {
data: 'YOUR_MAPTILER_DATASET_ID_HERE',
property: "mag",
pointColor: ColorRampCollection.VIRIDIS.scale(1, 5),
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex">
<title>Point layer colored and sized according to a property (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.