wrld.js

Querying indoor map entities

Click on the 'Go to floor' button to navigate indoors and click on the two meeting rooms or the desks to highlight them.

<!DOCTYPE HTML>
<html>
  <head>
    <script src="https://cdn-webgl.wrld3d.com/wrldjs/dist/latest/wrld.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.1/leaflet.css" rel="stylesheet" />
    <style>
      #floorButtons {
        position: absolute;
        z-index: 20;
      }

      #floorButtons button {
        display: block;
        width: 100%;
      }
    </style>
  </head>
  
  <body>
  <div style="position: relative">
    <div id="floorButtons">
      <button onclick="toFloor()">Go to floor</button>
    </div>
    <div id="map" style="height: 400px"></div>

    <script>
      var map = L.Wrld.map("map", "your_api_key_here", {
        center: [56.459801, -2.977928],
        zoom: 15,
        indoorsEnabled: true
      });

      var entityIdsToColorIndex = {};
      var colors = [
          [255, 0, 0, 128],
          [0, 255, 0, 128],
          [0, 0, 255, 128],
      ];

      function onIndoorEntityClicked(event) {
        var id = event.ids[0];
        entityIdsToColorIndex[id] = entityIdsToColorIndex[id] === undefined ? 0 : (entityIdsToColorIndex[id] + 1) % colors.length;
        map.indoors.setEntityHighlights(id, colors[entityIdsToColorIndex[id]]);
      }

      function toFloor() {
        map.indoors.enter("westport_house");
      }

      function onIndoorMapEntered() {
        map.indoors.setFloor(2);
        map.setView([56.459984, -2.978238], 20);
      }

      map.indoors.on("indoormapenter", onIndoorMapEntered);
      map.indoors.on("indoorentityclick", onIndoorEntityClicked);
    </script>

  </div>
  </body>
</html>
v0.1.1452