Adding a custom raster layer

Adding a custom raster layer

This example will render the satellite-geocolor AerisWeather Maps raster layer using a custom data source and adjusting its opacity.

add-raster-layer.html
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>MapsGL SDK - Adding a custom raster layer</title>
    <meta name="description" content="Add a custom raster tile layer to the map." />
    <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: [12.35666, 45.34880],
                zoom: 3
            });
 
            const account = new aerisweather.mapsgl.Account('CLIENT_ID', 'CLIENT_SECRET');
            const controller = new aerisweather.mapsgl.MapboxMapController(map, { account });
            
            controller.on('load', () => {
  
                // add the raster data tile source 
                controller.addSource('satellite-geocolor', {
                    type: 'raster',
                    url: 'https://maps{s}.aerisapi.com/{client_id}_{client_secret}/satellite-geocolor/{z}/{x}/{y}/0@2x.png'
                });
 
                // add the raster layer and associate it with the data source
                controller.addLayer('satellite', {
                    type: 'raster',
                    source: 'satellite-geocolor',
                    paint: {
                        raster: {
                            opacity: 0.7
                        }
                    }
                });
 
            });
        });
 
    </script>
</body>
</html>