Render Shapes - Polylines

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

HTML

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

    <!-- jsFiddle will insert css and js -->
  </head>
  <body>
    <!--The div element for the map -->
    <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",
      });
    </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;
}

JavaScript

// Initialize and add the map
let map;

async function initMap() {
  await woosmap.map.importLibrary("maps");
  map = document.getElementById("map").innerMap;
  map.moveCamera({
    center: { lat: 51.505, lng: -0.118 },
    zoom: 15,
  });

  //Polyline Shape
  const polylinePath = [
    { lng: -0.12638568878173828, lat: 51.50099581189912 },
    { lng: -0.12201905250549315, lat: 51.500832183172456 },
    { lng: -0.11891841888427736, lat: 51.50078877137083 },
    { lng: -0.11869311332702637, lat: 51.500832183172456 },
    { lng: -0.11754512786865233, lat: 51.500752038275635 },
    { lng: -0.11698186397552489, lat: 51.50050158456475 },
    { lng: -0.11669218540191649, lat: 51.50048488760175 },
    { lng: -0.11619329452514648, lat: 51.500688590132405 },
    { lng: -0.11590898036956787, lat: 51.50086557683785 },
    { lng: -0.1160377264022827, lat: 51.50112270724184 },
    { lng: -0.11700868606567383, lat: 51.50142992608211 },
    { lng: -0.11710524559020995, lat: 51.50164364231471 },
    { lng: -0.1157534122467041, lat: 51.50321309019227 },
    { lng: -0.11474490165710448, lat: 51.50420148069069 },
    { lng: -0.11411190032958984, lat: 51.50454874793857 },
    { lng: -0.11415, lat: 51.50545363381515 },
    { lng: -0.11816740036010741, lat: 51.50991769706187 },
  ];
  //Polyline Object with Path as an Array of LatLng
  const polyline = new woosmap.map.Polyline({
    path: polylinePath,
    strokeColor: "#b71c1c",
    strokeOpacity: 0.8,
    strokeWeight: 4,
  });

  polyline.setMap(map);
}

initMap();