Jump Through Locations
Use map.jumpTo() on an interval to step instantly through a list of coordinates - here a world tour of major cities.
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: [-74.006, 40.7128], zoom: 11 }); // New York
const places = [[-74.006, 40.7128], [-0.1276, 51.5074], [139.7671, 35.6812], [151.2093, -33.8688], [-43.1729, -22.9068]];
let i = 0;
map.on('load', function () {
setTimeout(function () {
setInterval(function () { i = (i + 1) % places.length; map.jumpTo({ center: places[i], zoom: 11 }); }, 3000);
}, 2000);
});
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: [-74.006, 40.7128], zoom: 11 }); // New York
const places = [[-74.006, 40.7128], [-0.1276, 51.5074], [139.7671, 35.6812], [151.2093, -33.8688], [-43.1729, -22.9068]];
let i = 0;
map.on('load', function () {
setTimeout(function () {
setInterval(function () { i = (i + 1) % places.length; map.jumpTo({ center: places[i], zoom: 11 }); }, 3000);
}, 2000);
});
map.addControl(new MaptoolkitLogoControl());
</script>
</body>
</html>