Skip to content

2 - Setting availability

This example shows how to set the full availability of a map.

Map Viewer

Code

// ---- LOADING MODULE ----
DVM.loadModule("map_viewer", {
    container: "viewer-container" // Container where the viewer will be appended
})
    .then(function(viewer) {
        console.log(`Module '${viewer.getModuleName()}' initialized:`, viewer);
        start(viewer);

    })
    .catch(function(err) {
        console.error(err);
    });


function start(viewer) {
    // ---- LOADING MAP ----
    viewer.loadMap({
        venue_id: "eu-es-00008-default" // Venue to be loaded. 3ddigitalvenue will provide these IDs
    })
        .then(function(obj) {
            // Successfully loaded

            // Get sections availability
            var available_sections = getSectionAvailability();
            // Apply sections availability
            viewer.setAvailability("section", available_sections);

            // Get seats availability
            var available_seats = getSeatAvailability();
            // Apply seats availability
            viewer.setAvailability("seat", available_seats);

            console.log("LOADED!");
        })
        .catch(function(err) {
            // Error while loading
            console.error(err);
        });


    // ---- AVAILABILITY FUNCTIONS ----
    // Get sections availability. For the purpose, we generate a RANDOM availability.
    function getSectionAvailability() {
        var sections = viewer.getNodesByType("section");
        var available_sections = [];

        for (var i = 0; i < sections.length; ++i) {
            var section = sections[i];
            if (Math.random() < 0.7) {
                available_sections.push(section.id);
            }
        }

        return available_sections;
    }


    // Get seats availability. For the purpose, we generate a RANDOM availability.
    function getSeatAvailability() {
        // Only generate availability for seats with an AVAILABLE parent section
        var available_sections = viewer.getNodesByState("section", "available");
        var available_seats = [];

        for (var i = 0; i < available_sections.length; ++i) {
            var section = available_sections[i];
            var seats = viewer.getNodesByParent(section.id);
            for (var j = 0; j < seats.length; ++j) {
                var seat = seats[j];
                if (Math.random() < 0.7) {
                    available_seats.push(seat.id);
                }
            }
        }

        return available_seats;
    }
}