For AI agents: a documentation index is available at /llms.txt. Markdown versions of all pages are available by appending .md to any URL.
Animate map camera around a point
Animate the map camera around a point.
NPM module setup
npm install --save @maptiler/sdk
import { Map, MapStyle, config } from "@maptiler/sdk";
import "@maptiler/sdk/dist/maptiler-sdk.css";
config.apiKey = "YOUR_MAPTILER_API_KEY_HERE";
const map = new Map({
container: "map",
style: MapStyle.STREETS,
center: [-87.62712, 41.89033],
zoom: 15.5,
pitch: 45,
});
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", function () {
// Start the animation.
rotateCamera(0);
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex">
<title>Animate map camera around a point</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div id="map"></div>
<script type="module" src="./main.js"></script>
</body>
</html>
body {margin: 0; padding: 0;}
#map {position: absolute; top: 0; bottom: 0; width: 100%;}
Related examples
Navigate the map with game-like controls
ExamplesNavigate map using keyboard arrow keys with game controls.
Creates an animated map to fly between different locations
ExamplesAnimate map flights between locations using a heatmap layer.
Customize camera animations
ExamplesCustomize map camera animations using the AnimationOptions property.