Draw Shapes - Handling Events

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

HTML

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

    <!-- jsFiddle will insert css and js -->
  </head>
  <body>
    <div id="container">
      <div id="map"></div>
      <div class="events" id="sidebar"></div>
    </div>

    <script
      src="https://sdk.woosmap.com/map/map.js?key=woos-e1e5490b-19d1-34f8-9955-fd5cfc8c880f&callback=initMap&libraries=drawing"
      defer
    ></script>
  </body>
</html>

CSS

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;
}

#container {
  height: 100%;
  display: flex;
}

#sidebar {
  flex-basis: 12rem;
  flex-grow: 1;
  max-width: 30rem;
  height: 100%;
  box-sizing: border-box;
  overflow: auto;
}

#map {
  flex-basis: 70vw;
  flex-grow: 5;
  height: 100%;
}

.events {
  font-family: "Droid Sans Mono", monospace;
}

.event {
  transition: background-color 0.5s ease-out;
  padding: 0.5em;
  overflow: hidden;
  font-size: 14px;
}

.active {
  background-color: #ffdd00;
  color: #000;
}

.inactive {
  background-color: white;
}

JavaScript

// Initialize and add the map
let map;
const events = [
  "draw.create",
  "draw.delete",
  "draw.modechange",
  "draw.selectionchange",
  "draw.update",
  "draw.combine",
  "draw.uncombine",
];
const data = {
  type: "FeatureCollection",
  features: [
    {
      id: "c40c2c23ce0c89dbc445b4dcc5913754",
      type: "Feature",
      properties: {},
      geometry: {
        coordinates: [
          [
            [-98.73532642865247, 30.126769329207107],
            [-99.58823422826457, 29.363810063756134],
            [-97.94703285628337, 28.640467970538566],
            [-96.84859099314622, 28.41338984007197],
            [-96.04737457532838, 28.867055658752506],
            [-95.37538661199761, 29.330016761277975],
            [-94.54832450328229, 29.846944934629335],
            [-94.9230870212941, 30.750699730175043],
            [-97.93411001083463, 30.950398105638087],
            [-98.73532642865247, 30.126769329207107],
          ],
        ],
        type: "Polygon",
      },
    },
    {
      id: "56cc82cc895f6cb52d87f75a7e94a904",
      type: "Feature",
      properties: {},
      geometry: {
        coordinates: [
          [
            [-98.27139781722337, 33.638565671747955],
            [-98.25118921584728, 32.02551092926721],
            [-95.62407103697022, 32.05977071105772],
            [-95.62407103697022, 33.65538867007554],
            [-98.27139781722337, 33.638565671747955],
          ],
        ],
        type: "Polygon",
      },
    },
  ],
};

function populateTable() {
  const eventsTable = document.getElementById("sidebar");
  let content = "";

  for (let i = 0; i < events.length; i++) {
    content += `<div class="event" id="${events[i]}">${events[i]}</div>`;
  }

  if (eventsTable) {
    eventsTable.innerHTML = content;
  }
}

function setupListener(name) {
  const eventRow = document.getElementById(name);

  if (eventRow) {
    eventRow.className = "event active";
    setTimeout(() => {
      eventRow.className = "event...