Customizing lightning point styles

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.

lightning-styles.html
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>MapsGL SDK - Customizing lightning point styles</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
 
    <link href="https://api.mapbox.com/mapbox-gl-js/{% $versions.mapbox.current %}/mapbox-gl.css" rel="stylesheet" />
    <script defer src="https://api.mapbox.com/mapbox-gl-js/{% $versions.mapbox.current %}/mapbox-gl.js"></script>
    
    <script defer src="{% $paths.sdk %}"></script>
    <link href="{% $paths.css %}" rel="stylesheet" />
 
    <style>
    #map {
        height: 600px;
        margin: 30px auto;
        width: 1200px;
    }
    </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>