Fly to a location
Animate the map to a place when a button is clicked.
Code
Replace YOUR_API_KEY with a key from your Gebeta dashboard, save the file as index.html and open it in a browser.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Fly to a location</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500&display=swap" />
<script src="https://tiles.gebeta.app/static/v3/gebeta-maps.umd.js"></script>
<style>
body { margin: 0; font: 13px/1.4 Geist, system-ui, sans-serif; color: #161616; }
#map { position: absolute; inset: 0; }
.panel { position: absolute; top: 12px; left: 12px; z-index: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; max-width: calc(100% - 24px); }
button { border: 0; border-radius: 999px; padding: 8px 14px; background: #fff; color: #161616; font: 500 13px Geist, system-ui, sans-serif; cursor: pointer; box-shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 0 0 1px rgb(0 0 0 / 0.1); transition: background-color 150ms cubic-bezier(0.215, 0.61, 0.355, 1); }
button:hover { background: #f4f4f4; }
button[aria-pressed="true"] { background: #191715; color: #faf9f7; }
</style>
</head>
<body>
<div id="map"></div>
<div class="panel"></div>
<script>
const places = [
{ name: "Meskel Square", center: [38.7613, 9.0106] },
{ name: "Bole Airport", center: [38.7993, 8.9779] },
{ name: "Piassa", center: [38.7505, 9.0336] },
{ name: "Merkato", center: [38.7369, 9.03] },
{ name: "Entoto", center: [38.767, 9.084] },
];
const gebeta = new GebetaMaps({ apiKey: "YOUR_API_KEY" });
const map = gebeta.init({
container: "map",
center: [38.7578, 9.0192],
zoom: 15,
});
const panel = document.querySelector(".panel");
places.forEach((place) => {
const button = document.createElement("button");
button.textContent = place.name;
button.addEventListener("click", () => {
map.flyTo({ center: place.center, zoom: 15, essential: true });
panel.querySelectorAll("button").forEach((other) => other.setAttribute("aria-pressed", String(other === button)));
});
panel.append(button);
});
</script>
</body>
</html>