Skip to content

Add terrain control

Add a terrain control to the map, to toggle 3D terrain and hillshading.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <script src="https://cdn.smartmaps.cloud/packages/smartmaps/smartmaps-gl/v2/umd/smartmaps-gl.min.js"></script>
        <style>
            html,
            body {
                height: 100vh;
                margin: 0;
                padding: 0;
            }

            #map {
                height: 100%;
            }
        </style>
    </head>

    <body>
        <div id="map"></div>
        <script>
            const map = new smartmapsgl.Map({
                apiKey: "INSERT API-KEY",
                container: "map",
                center: [11.39085, 47.27574],
                pitch: 50,
                zoom: 12,
                style: smartmapsgl.MapStyle.AUTO,
                // boolean | TerrainOptions
                terrain: {

                    // Controls the vertical exaggeration of the terrain.
                    // A value of 1 means no exaggeration, higher values amplify the terrain's height.
                    exaggeration: 1,

                    // Specifies the position of the terrain control on the map.
                    position: 'top-right',

                    // Determines whether the terrain control is activated by default.
                    activated: true

                }
            });
        </script>
    </body>
</html>