Skip to content

Animate camera around a point

Animate the map camera around a specific point.

<!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>
            body {
                margin: 0;
                padding: 0;
            }

            html,
            body,
            #map {
                height: 400px;
            }
        </style>
    </head>

    <body>
        <div id="map"></div>
        <script>
            const map = new smartmapsgl.Map({
                apiKey: "INSERT API-KEY",
                container: "map",
                center: [13.377702, 52.51628],
                zoom: 17,
                pitch: 45,
                style: smartmapsgl.MapStyle.AUTO
            });

            function rotateCamera(timestamp) {
                // clamp the rotation between 0 -360 degrees
                // Divide timestamp by 100 to slow rotation to ~10 degrees / sec
                map.rotateTo((timestamp / 100) % 360, { duration: 0 });
                // Request the next frame of the animation.
                requestAnimationFrame(rotateCamera);
            }

            map.on('load', () => {
                // Start the animation.
                rotateCamera(0);

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