Skip to content

Rotate Around a Point

Drive map.rotateTo() from requestAnimationFrame to orbit the bearing around the current center for a rotating showcase view, here over the Colosseum in Rome.

import { MaptoolkitLogoControl } from 'https://cdn.jsdelivr.net/npm/@maptoolkit/maplibre-gl-logo/+esm';
const map = new maplibregl.Map({ container: 'map', attributionControl: { customAttribution: '' }, style: 'https://styles.maptoolkit.org/summer.json', center: [12.4922, 41.8902], zoom: 15, pitch: 60 }); // Colosseum, Rome
map.on('load', function () {
  function spin(t) { map.rotateTo((t / 120) % 360, { duration: 0 }); requestAnimationFrame(spin); }
  requestAnimationFrame(spin);
});
map.addControl(new MaptoolkitLogoControl());
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/maplibre-gl.js"></script>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/maplibre-gl.css" />
  <style>
    html, body { width: 100%; height: 100%; margin: 0; padding: 0; }
    #map { width: 100%; height: 100%; }
  </style>
</head>
<body>
  <div id="map"></div>
  <script type="module">
import { MaptoolkitLogoControl } from 'https://cdn.jsdelivr.net/npm/@maptoolkit/maplibre-gl-logo/+esm';
const map = new maplibregl.Map({ container: 'map', attributionControl: { customAttribution: '' }, style: 'https://styles.maptoolkit.org/summer.json', center: [12.4922, 41.8902], zoom: 15, pitch: 60 }); // Colosseum, Rome
map.on('load', function () {
  function spin(t) { map.rotateTo((t / 120) % 360, { duration: 0 }); requestAnimationFrame(spin); }
  requestAnimationFrame(spin);
});
map.addControl(new MaptoolkitLogoControl());
  </script>
</body>
</html>