Adding a custom vector tile layer

Adding a custom vector tile layer

This example renders a custom vector tile layer on the map using vector tiles from Nextzen (opens in a new tab) to render water boundaries.

add-vector-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 vector tile layer</title>
    <meta name="description" content="Add a custom vector 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: [-30.33207, 40.60621],
                zoom: 2
            });
 
            const account = new aerisweather.mapsgl.Account('CLIENT_ID', 'CLIENT_SECRET');
            const controller = new aerisweather.mapsgl.MapboxMapController(map, { account });
            
            controller.on('load', () => {
 
                controller.addSource('base', {
                    type: 'vector',
                    url: 'https://tile.nextzen.org/tilezen/vector/v1/256/all/{z}/{x}/{y}.mvt?api_key={nextzen_key}'
                });
                
                controller.addLayer('boundaries', {
                    type: 'line',
                    source: 'base',
                    sourceType: 'line',
                    sourceLayer: 'water',
                    paint: {
                        stroke: {
                            color: '#333333',
                            opacity: 1,
                            thickness: 2,
                            lineCap: 'round',
                            lineJoin: 'round'
                        }
                    }
                });
            });
        });
 
    </script>
</body>
</html>