Data-Driven Circles
Use expressions to drive paint from feature data. Here circle-radius interpolates and circle-color steps on a mag property.
import { MaptoolkitLogoControl } from 'https://cdn.jsdelivr.net/npm/@maptoolkit/maplibre-gl-logo/+esm';
const map = new maplibregl.Map({ container: 'map', attributionControl: { customAttribution: '' }, style: 'https://styles.maptoolkit.org/summer.json', center: [4, 48], zoom: 3.3 });
const fc = { type: 'FeatureCollection', features: [
{ type: 'Feature', properties: { mag: 1 }, geometry: { type: 'Point', coordinates: [13.405, 52.52] } },
{ type: 'Feature', properties: { mag: 3 }, geometry: { type: 'Point', coordinates: [2.3522, 48.8566] } },
{ type: 'Feature', properties: { mag: 5 }, geometry: { type: 'Point', coordinates: [-0.1276, 51.5074] } },
{ type: 'Feature', properties: { mag: 2 }, geometry: { type: 'Point', coordinates: [-3.7038, 40.4168] } }
] };
map.on('load', function () {
map.addSource('quakes', { type: 'geojson', data: fc });
map.addLayer({ id: 'quakes', type: 'circle', source: 'quakes', paint: {
'circle-radius': ['interpolate', ['linear'], ['get', 'mag'], 1, 6, 5, 28],
'circle-color': ['step', ['get', 'mag'], '#2c7bb6', 2, '#fdae61', 4, '#d7191c'],
'circle-opacity': 0.8, 'circle-stroke-width': 1, 'circle-stroke-color': '#fff'
} });
});
map.addControl(new MaptoolkitLogoControl());<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/maplibre-gl.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/maplibre-gl.css" />
<style>
html, body { width: 100%; height: 100%; margin: 0; padding: 0; }
#map { width: 100%; height: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script type="module">
import { MaptoolkitLogoControl } from 'https://cdn.jsdelivr.net/npm/@maptoolkit/maplibre-gl-logo/+esm';
const map = new maplibregl.Map({ container: 'map', attributionControl: { customAttribution: '' }, style: 'https://styles.maptoolkit.org/summer.json', center: [4, 48], zoom: 3.3 });
const fc = { type: 'FeatureCollection', features: [
{ type: 'Feature', properties: { mag: 1 }, geometry: { type: 'Point', coordinates: [13.405, 52.52] } },
{ type: 'Feature', properties: { mag: 3 }, geometry: { type: 'Point', coordinates: [2.3522, 48.8566] } },
{ type: 'Feature', properties: { mag: 5 }, geometry: { type: 'Point', coordinates: [-0.1276, 51.5074] } },
{ type: 'Feature', properties: { mag: 2 }, geometry: { type: 'Point', coordinates: [-3.7038, 40.4168] } }
] };
map.on('load', function () {
map.addSource('quakes', { type: 'geojson', data: fc });
map.addLayer({ id: 'quakes', type: 'circle', source: 'quakes', paint: {
'circle-radius': ['interpolate', ['linear'], ['get', 'mag'], 1, 6, 5, 28],
'circle-color': ['step', ['get', 'mag'], '#2c7bb6', 2, '#fdae61', 4, '#d7191c'],
'circle-opacity': 0.8, 'circle-stroke-width': 1, 'circle-stroke-color': '#fff'
} });
});
map.addControl(new MaptoolkitLogoControl());
</script>
</body>
</html>