All examples

Custom marker images

Use your own marker image and show a popup when it's 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>Custom marker images</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; }

      .maplibregl-popup-content { padding: 10px 14px; border-radius: 8px; font: 13px/1.4 Geist, system-ui, sans-serif; box-shadow: 0 16px 40px rgb(0 0 0 / 0.12), 0 0 0 1px rgb(0 0 0 / 0.08); }
      .maplibregl-popup-content strong { font-weight: 500; }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>
      const cafes = [
        { id: "tomoca", name: "Tomoca Coffee", color: "#2563eb", lngLat: [38.7527, 9.0339] },
        { id: "kaldis", name: "Kaldi's Coffee", color: "#dc2626", lngLat: [38.7886, 8.9958] },
        { id: "garden", name: "Garden of Coffee", color: "#16a34a", lngLat: [38.7712, 9.0188] },
        { id: "galani", name: "Galani Cafe", color: "#9333ea", lngLat: [38.7642, 9.0044] },
      ];

      function pinImage(color) {
        const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 42 136"><path fill="${color}" stroke="#fff" stroke-width="2" d="M21 1a20 20 0 0 1 2 39.9V64a2 2 0 0 1-4 0V40.9A20 20 0 0 1 21 1Z"/><circle cx="21" cy="21" r="7" fill="#fff"/></svg>`;
        return "data:image/svg+xml," + encodeURIComponent(svg);
      }

      const gebeta = new GebetaMaps({
        apiKey: "YOUR_API_KEY",
        clustering: { enabled: true },
      });

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

      map.on("load", () => {
        cafes.forEach((cafe) => {
          gebeta.clustering.addMarker({
            id: cafe.id,
            lngLat: cafe.lngLat,
            imageUrl: pinImage(cafe.color),
            size: [28, 90],
            popupContent: `<strong>${cafe.name}</strong>`,
          });
        });
      });
    </script>
  </body>
</html>