// ---- LOADING MODULE ----
DVM.loadModule("map_viewer", {
container: "viewer-container",
})
.then(function (viewer) {
window.viewer = viewer;
start(viewer);
})
.catch(function (err) {
console.error(err);
});
function start(viewer) {
// ---- LOADING MAP ----
var tooltip = document.getElementById("tooltip");
var tooltip_node_id = null;
var container = document.getElementById("viewer-container");
var popper = null;
var timeout = null;
viewer.subscribe("enter", function (obj) {
var node = obj.nodes[0];
if (node) {
createPopup(node);
}
});
viewer.subscribe("leave", function (obj) {
destroyPopper();
});
viewer.subscribe("zooming", function () {
updatePopup();
});
viewer.subscribe("panning", function () {
updatePopup();
});
function updatePopup() {
if (popper) {
popper.update();
var node = viewer.getNodeById(tooltip_node_id);
if (node && node.on_screen) {
showPopup();
} else {
hidePopup();
}
}
}
function createPopup(node) {
clearTimeout(timeout);
tooltip_node_id = node.id;
timeout = setTimeout(function() {
popper = Popper.createPopper(node, tooltip, {
placement: "top",
modifiers: [
{
name: "flip",
options: {
fallbackPlacements: ["bottom", "left", "right"],
},
},
{
name: "preventOverflow",
options: {
boundary: container,
},
},
],
});
tooltip.innerText = "Node: " + node.id;
showPopup();
}, 250);
}
function showPopup() {
tooltip.style.display = "initial";
tooltip.style.visibility = "initial";
tooltip.style.pointerEvents = "initial";
}
function hidePopup() {
tooltip.style.visibility = "hidden";
tooltip.style.pointerEvents = "none";
}
function destroyPopper() {
if (popper) {
popper.destroy();
popper = null;
tooltip_node_id = null;
tooltip.style.display = "none";
}
}
// Load the map
viewer
.loadMap({
venue_id: "eu-es-00008-default",
})
.then(function (obj) {
// Successfully loaded
console.log("LOADED!");
})
.catch(function (err) {
// Error while loading
console.error(err);
});
}