Marker HTML CSS

Sample code for Woosmap Map JavaScript API author(s): Woosmap

HTML

<!DOCTYPE html>
<html>
  <head>
    <title>Marker HTML CSS</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta charset="utf-8" />

    <!-- jsFiddle will insert css and js -->
  </head>
  <body>
    <wmp-map id="map"></wmp-map>

    <script>
      (g=>{var p,w=window,d=document,l="importLibrary",q="__ib__",e="The Woosmap Maps JavaScript API",o=w.woosmap||(w.woosmap={}),m=o.map||(o.map={}),r=new Set(String(g.libraries||"").split(",").filter(Boolean)),s=new URLSearchParams,u=()=>p||(p=new Promise((f,n)=>{var a=d.createElement("script");s.set("libraries",[...r]+"");for(var k in g)k!="libraries"&&g[k]&&s.set(k,g[k]);s.set("callback","woosmap.map."+q);a.src="https://sdk.woosmap.com/map/map.js?"+s;m[q]=f;a.onerror=()=>n(Error(e+" could not load."));a.nonce=d.querySelector("script[nonce]")?.nonce||"";d.head.append(a)}));m[l]?console.warn(e+" only loads once. Ignoring:",g):m[l]=(f,...n)=>r.add(f)&&u().then(()=>m[l](f,...n))})({
        key: "woos-e1e5490b-19d1-34f8-9955-fd5cfc8c880f",
        libraries: "marker",
      });
    </script>
  </body>
</html>

CSS

/*
 * Always set the map height explicitly to define the size of the element
 * that contains the map. `display: block` is required for <wmp-map>/<gmp-map>,
 * which default to inline like any other custom element outside a flex/grid
 * container (no-op for a plain <div>).
 */
#map {
  display: block;
  width: 100%;
  height: 100%;
}

/*
 * Optional: Makes the sample page fill the window.
 */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji;
}

.popover {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  cursor: pointer;
}
.popover .popover-content {
  display: flex;
  align-items: center;
  background-color: #FFF;
  color: #1D1D1D;
  padding: 6px 8px;
  border-radius: 20px;
  font-family: Roboto, Arial, sans-serif;
  font-size: 15px;
  font-weight: 500;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  z-index: 1;
}
.popover .popover-content .icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: #f50057;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  margin-right: 6px;
  background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAtOTYwIDk2MCA5NjAiIHdpZHRoPSIyNHB4IiBmaWxsPSIjRkZGRkZGIj48cGF0aCBkPSJNNDAtMjAwdi02MDBoODB2NDAwaDMyMHYtMzIwaDMyMHE2NiAwIDExMyA0N3Q0NyAxMTN2MzYwaC04MHYtMTIwSDEyMHYxMjBINDBabTI0MC0yNDBxLTUwIDAtODUtMzV0LTM1LTg1cTAtNTAgMzUtODV0ODUtMzVxNTAgMCA4NSAzNXQzNSA4NXEwIDUwLTM1IDg1dC04NSAzNVoiLz48L3N2Zz4=");
  background-repeat: no-repeat;
  background-size: 16px 16px;
  background-position: center;
}
.popover .popover-content .price {
  white-space: nowrap;
}
.popover .popover-arrow-shadow {
  position: absolute;
  bottom: -7px;
  left: 50%;
 ...

JavaScript

async function initMap() {
  await woosmap.map.importLibrary("maps");
  await woosmap.map.importLibrary("marker");

  function createMarkerContent(data) {
    const div = document.createElement("div");

    div.className = "popover";
    div.innerHTML = `<div class="popover-content">
                      <span class="icon">️</span>
                      <span class="price">${data.price}</span>
                    </div>
                     <div class="popover-arrow-shadow"></div>
                     <div class="popover-arrow"></div>`;
    return div;
  }

  const center = { lat: 51.5074, lng: -0.1278 };
  const map = document.getElementById("map").innerMap;

  map.moveCamera({
    zoom: 13,
    center: center,
  });

  const markersData = [
    { price: "100 €" },
    { price: "200 €" },
    { price: "300 €" },
    { price: "400 €" },
    { price: "500 €" },
  ];
  const positions = [
    { lat: 51.5074, lng: -0.1278 },
    { lat: 51.5174, lng: -0.1378 },
    { lat: 51.4974, lng: -0.1178 },
    { lat: 51.5074, lng: -0.1478 },
    { lat: 51.5074, lng: -0.1078 },
  ];
  const markers = [];

  markersData.forEach((data, index) => {
    const content = createMarkerContent(data);
    const marker = new woosmap.map.marker.AdvancedMarkerElement({
      position: positions[index],
      map: map,
      content,
      gmpClickable: true,
    });

    marker.addListener("click", () => {
      markers.forEach((m) => {
        m.content.classList.remove("active");
      });
      content.classList.add("active");
    });
    markers.push(marker);
  });
}

initMap();