// The default values will get you going quickly and when you're ready. Try swapping them out with your provided API Key and a Unit Map ID.
var API_KEY = 'lXIPNcwOVgXsjAhJLr5C2iTRP4lPpusS';
var UNIT_MAP_ID = '5236';
// Create a unitmap instance, telling it which DOM element it should bind to along with your API Key.
var map = unitmap('map', API_KEY);
// Load a Unit Map.
map.load(UNIT_MAP_ID);
// When the Unit Map is loaded, we can begin interacting with it.
// Get list of unit IDs and numbers
var data = JSON.stringify(false);
var xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === this.DONE) {
const {
data
} = JSON.parse(this.responseText);
const oneBedUnits = data.reduce(function(carry, unit) {
carry.push(unit.id);
return carry;
}, []);
map.on('ready', function() {
map.maxScale(5);
// Display the floor that matches the ID 12696
var floors = map.levels().has({
floor: true
});
floors.except({
floor: "21077",
}).hide();
// Floor selector
var floorSelector = $('#floors');
floorSelector.on("change", function(event) {
floors.except({
floor: this.value,
}).hide();
floors.where({
floor: this.value,
}).show();
});
// Unit colors
var oneBed = "rgba(232,178,80,0.54)";
var activeOneBed = "#e4b350";
// Compile unit IDs
map.units().find(oneBedUnits).color(oneBed);
// Add events to listen for unit interaction. For this example, we are tracking the unit the user interacts with.
// Reference to the active unit.
var activeUnit;
var i = 0;
map.on('unit:click', function(event) {
if (isActive(event.unit)) {
return;
}
activeUnit = event.unit;
// When a user selects a unit, it is activated.
// ...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.