All examples

Find what's at a point

Click the map to look up the nearest named place.

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>Find what's at a point</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; }

      .card { position: absolute; top: 12px; left: 12px; z-index: 1; max-width: calc(100% - 52px); padding: 10px 14px; border-radius: 8px; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 0 0 1px rgb(0 0 0 / 0.07); }
      .card strong { display: block; font-weight: 500; }
      .card small { color: #8a8a8a; font-size: 13px; }

      .pin { width: 28px; height: 45px; filter: drop-shadow(0 0 1px #fff) drop-shadow(0 0 1px #fff); }
      .pin span { position: absolute; top: -4px; left: 20px; min-width: 16px; height: 16px; padding: 0 4px; box-sizing: border-box; border: 1px solid #fff; border-radius: 999px; background: #191715; color: #faf9f7; font: 500 10px/14px Geist, system-ui, sans-serif; text-align: center; }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <div class="card"><strong>Click the map</strong><small>The nearest place appears here.</small></div>
    <script>
      const INK = "#191715";

      function pin(color, label) {
        const element = document.createElement("div");
        element.className = "pin";
        element.innerHTML = `<svg width="28" height="45" viewBox="0 0 42 68"><path fill="${color}" d="M21 0a21 21 0 0 1 2 41.9V64a2 2 0 0 1-4 0V41.9A21 21 0 0 1 21 0Z"/><circle cx="21" cy="21" r="7" fill="#fff"/></svg>`;
        if (label) element.insertAdjacentHTML("beforeend", `<span>${label}</span>`);
        return element;
      }

      const { Marker } = window.gebeta;

      const gebeta = new GebetaMaps({ apiKey: "YOUR_API_KEY" });

      const map = gebeta.init({
        container: "map",
        center: [38.7578, 9.0192],
        zoom: 15,
      });

      const card = document.querySelector(".card");
      const marker = new Marker({ element: pin(INK), anchor: "bottom" });

      map.getCanvas().style.cursor = "crosshair";

      map.on("click", async (event) => {
        card.innerHTML = "<strong>Looking up…</strong>";
        const places = await gebeta.geocodingManager.reverseGeocode(event.lngLat);
        const nearest = places[0];

        if (!nearest) {
          card.innerHTML = "<strong>Nothing found here</strong>";
          return;
        }
        marker.setLngLat(nearest.lngLat).addTo(map);
        card.innerHTML = `<strong>${nearest.name}</strong><small>${nearest.type} · ${nearest.City}</small>`;
      });
    </script>
  </body>
</html>