Customizing wind particles
This example configures the wind-particles
weather layer with a custom normalized color scale and different particle generation settings.
custom-wind-particles.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>MapsGL SDK - Customizing wind particles</title>
<meta name="description" content="Use a custom color scale and particle settings with the wind particles layer." />
<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>
<link href="https://cdn.aerisapi.com/sdk/js/mapsgl/latest/aerisweather.mapsgl.css" rel="stylesheet" />
<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/light-v9',
center: [10.33207, 47.60621],
zoom: 3
});
const account = new aerisweather.mapsgl.Account('CLIENT_ID', 'CLIENT_SECRET');
const controller = new aerisweather.mapsgl.MapboxMapController(map, { account });
controller.on('load', () => {
controller.addWeatherLayer('wind-particles', {
paint: {
sample: {
colorscale: {
normalized: true,
stops: [
0, '#0b0089',
0.25, '#8800a8',
0.5, '#cf4875',
0.75, '#f99336',
1, '#f0fb00'
]
}
},
particle: {
count: Math.pow(256, 2), // using a power of two, e.g. 65536
size: 1,
speed: 2,
trailsFade: 0.9
}
}
});
});
});
</script>
</body>
</html>