MapsGL - Customizing lightning point styles
This example customizes the circle styles of the lightning-strikes weather layer by adjusting the circle fill color and opacity based on the age of each lightning strike.
custom-lightning-styles.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>MapsGL SDK - Custom lightning strike styling</title>
<meta name="description" content="Customize the appearance of lightning strike data based on strike age." />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="https://api.mapbox.com/mapbox-gl-js/v3.12.0/mapbox-gl.css" rel="stylesheet" />
<script defer src="https://api.mapbox.com/mapbox-gl-js/v3.12.0/mapbox-gl.js"></script>
<link href="https://cdn.aerisapi.com/sdk/js/mapsgl/1.9.4/aerisweather.mapsgl.css" rel="stylesheet" />
<script defer src="https://cdn.aerisapi.com/sdk/js/mapsgl/1.9.4/aerisweather.mapsgl.js"></script>
<style>
body, html {
margin: 0;
padding: 0;
}
#map {
height: 100vh;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
window.addEventListener('load', () => {
mapboxgl.accessToken = 'MAPBOX_TOKEN';
const map = new mapboxgl.Map({
container: document.getElementById('map'),
style: 'mapbox://styles/mapbox/dark-v9',
center: [-84.5, 30],
zoom: 5
});
const account = new aerisweather.mapsgl.Account('CLIENT_ID', 'CLIENT_SECRET');
const controller = new aerisweather.mapsgl.MapboxMapController(map, { account });
controller.on('load', () => {
// style lightning strike circles based on age
controller.addWeatherLayer('lightning-strikes', {
paint: {
fill: {
color: [
'step',
['coalesce', ['get', 'age'], 0],
'#ffffff',
61, 'rgba(255, 255, 255, 0.7)',
301, 'rgba(255, 255, 255, 0.5)',
601, 'rgba(255, 255, 255, 0.3)'
],
opacity: [
'step',
['coalesce', ['get', 'age'], 0],
1,
61, 0.8,
301, 0.6,
601, 0.4
]
},
stroke: {
color: '#fff',
thickness: 1
},
circle: {
radius: 4
}
}
});
});
});
</script>
</body>
</html>