Skip to content

Fly To a Location

map.flyTo() animates center, zoom, and bearing together along a curved path. Click the button to fly from the overview to Paris.

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: [5, 48], zoom: 3.5 });
document.getElementById('fly').addEventListener('click', function () {
  map.flyTo({ center: [2.3522, 48.8566], zoom: 12, speed: 0.8, curve: 1.4, essential: true });
});
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>
  <button id="fly" style="position:absolute;top:10px;left:10px;z-index:1;padding:6px 10px;border:none;border-radius:4px;background:#1a73e8;color:#fff;cursor:pointer;font:13px system-ui,sans-serif">Fly to Paris</button>
  <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: [5, 48], zoom: 3.5 });
document.getElementById('fly').addEventListener('click', function () {
  map.flyTo({ center: [2.3522, 48.8566], zoom: 12, speed: 0.8, curve: 1.4, essential: true });
});
map.addControl(new MaptoolkitLogoControl());
  </script>
</body>
</html>