SightMap Javascript API

IMT Test

by Jacob Pearlstein

HTML

<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>SightMap JavaScript IFrame API Example</title>
    <script src="https://sightmap.com/embed/api.js">


    </script>
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" type="text/css">

  </head>

  <body>
    <!-- The API script must be included on the page -->


    <!--
    Include the IFrame embed code. The embed URL must include `enable_api=1` and provide the pages origin. Additionally, the iframe must declare an id attribute, in this case it is set to `sightmap`.
    -->
    <div class="margin">
      <div class="head-container">
        <div class="title">
          <div class="textbox">
            Welcome to SightMap
          </div>
        </div>
        <!--
        <nav class="container">
          <a href class="nav-button">
            Floor G
          </a>
          <a href class="nav-button">
            Floor 1
          </a>
          <a href class="nav-button">
            Floor 2
          </a>
          <a href class="nav-button">
            Floor 3
          </a>
          <a href class="nav-button">
            Floor 4
          </a>
          <a href class="nav-button">
            Floor 5
          </a>
          <a href class="nav-button">
            Floor 6
          </a>
        </nav>
        -->

        <div class="row mt-5">
          <div class="col-md-4">
            <button class="btn btn-primary mb-2" id="disable-ui"><span id="disable-ui-button-text">Disable</span> All UI</button>
            <button class="btn btn-primary mb-2" id="disable-unit-list"><span id="disable-unit-list-button-text">Disable</span>  Unit List</button>
            <button class="btn btn-primary mb-2" id="disable-filters"><span id="disable-filters-button-text">Disable</span> ...

CSS

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0 auto;
  padding: 0;
  font-family: open sans, sans-serif;
}

.margin {
  margin: 20px;
  height: 75%;
}

.head-container {
  width: 95%;
  margin: auto;
}

nav.container {
  display: block;
  background-color: #333333;
  text-align: center;
  margin: auto;
}

.nav-button {
  text-align: center;
  color: white;
  width: 100%;
}

.sightmap-container {
  height: 75%;
  min-height: 600px;
  align-items: center;
  justify-content: center;
}

.title {
  background-color: hsl(211, 38%, 61%);
  color: white;
  margin: auto;
  height: 15%;
}

.textbox {
  text-align: center;
  line-height: 233%;
  font-size: 40pt;
}

.button-list {
  display: flex;
  flex-direction: row;
}

JavaScript

$('document').ready(function() {
  // Create a new embed instance, providing the IFrame id value:
  var embed = new SightMap.Embed('sightmap');

  console.log(embed);

  embed.on('ready', function() {
    console.log('hello world');
    // embed.setFloor(11703);
   //  embed.disableUI(['filters', 'floorSelection']);
  });
  
  // Start Metrics API

  embed.on('metrics.unitList.impression', function(event) {
    console.log(event);
  });

  embed.on('metrics.unitList.change', function(event) {
    console.log(event);
  });

  embed.on('metrics.unitList.unit.click', function(event) {
    console.log(event);
  });

  embed.on('metrics.unitMap.unit.click', function(event) {
    console.log(event);
  });

  embed.on('metrics.unitDetails.apply.click', function(event) {
    console.log(event);
  });
  
  // End Metrics API

  embed.on('floor:change', function(event) {
    console.log('floor id is now: ', event.id)
  })

  $("#get-floor").on('click', function(event) {
    embed.getFloor(function(id) {
      console.log('Active Floor ID:', id);
    })
  })

  $("#set-floor-button").on('click', function(event) {
    var value = $("#set-floor").val()
    embed.setFloor(value)
  })

  $("#display-unit-numbers-button").on('click', function(event) {
    var value = $("#display-unit-numbers").val().split(",")
    embed.setUnitNumberMatches(value, {filterEditing: true})
  })

  $("#locate-unit-number-button").on('click', function(event) {
    var value = $("#locate-unit-number").val()
    embed.locateUnitByUnitNumber(value)
  })

  var state = {
    disable_ui: true,
    disable_filters: true,
    disable_unit_list: true,
  }

  $('#disable-ui').on('click', function() {
    console.log('Disable / Enable All');
    if (state.disable_ui) {
      embed.disableUI(['unitList', 'filters', 'floorSelection']);
    } else {
      embed.disableUI([]);
    }
    state.disable_ui = !state.disable_ui;
    $("#disable-ui-button-text").text(state.disable_ui ? 'Disable' : 'Enable');
  });

 ...