Custom lightning strike styling

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/v2.8.0/mapbox-gl.css' rel='stylesheet' />
 
    <script defer src='https://api.mapbox.com/mapbox-gl-js/v2.8.0/mapbox-gl.js'></script>
    <script defer src="https://cdn.aerisapi.com/sdk/js/mapsgl/latest/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: (data) => {
                                const age = data.age || 0;
                                if (age <= 60) {
                                    return '#ffffff';
                                } else if (age <= 300) {
                                    return 'rgba(255, 255, 255, 0.7)';
                                } else if (age <= 600) {
                                    return 'rgba(255, 255, 255, 0.5)';
                                }
                                return 'rgba(255, 255, 255, 0.3)';
                            },
                            opacity: (data) => {
                                const age = data.age || 0;
                                if (age <= 60) {
                                    return 1;
                                } else if (age <= 300) {
                                    return 0.8;
                                } else if (age <= 600) {
                                    return 0.6;
                                }
                                return 0.4;
                            }
                        },
                        stroke: {
                            color: '#fff',
                            thickness: 1
                        },
                        circle: {
                            radius: 4
                        }
                    }
                });
 
            });
        });
    </script>
 
</body>
</html>