Custom Floor Selector

To implement a custom floor selector, we expect you to already have completed the Getting Started Tutorial.

This guide will walk you through the process of implementing a custom floor selector using the MapsIndoors JavaScript SDK. The custom floor selector provides a more flexible and visually appealing way to switch between floors in your MapsIndoors-enabled application.

Prerequisites

Before you begin, make sure you have completed the getting started tutorial for the MapsIndoors JavaScript SDK. You should have a basic MapsIndoors map set up in your project.

Implementation

Step 1: Create the CustomFloorSelector Class

First, we'll create a CustomFloorSelector class that will handle the creation and management of our custom floor selector.

class CustomFloorSelector {
    constructor(mapsIndoorsInstance) {
        this.mapsIndoors = mapsIndoorsInstance;
        this.element = this.createSelectorElement();
        this.floors = {};
    }

    createSelectorElement() {
        const container = document.createElement('div');
        container.style.cssText = `
            position: absolute;
            top: 20px;
            right: 20px;
            background: rgba(30, 30, 30, 0.8);
            padding: 10px;
            border-radius: 15px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
            display: flex;
            flex-direction: column;
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.1);
            transition: all 0.3s ease;
        `;
        return container;
    }

    // ... (other methods will be added here)
}

Step 2: Implement Floor Management Methods

Add methods to handle showing, hiding, and updating the floor selector:

Step 3: Implement Floor Button Creation and Updating

Add methods to create and update the floor buttons:

Step 4: Initialize MapsIndoors and CustomFloorSelector

Now, let's initialize MapsIndoors and our custom floor selector:

Step 5: Set Up Event Listeners

Finally, set up event listeners to update the floor selector when necessary:

Customization

You can customize the appearance of the floor selector by modifying the CSS styles in the createSelectorElement and updateFloorButtons methods. Adjust colors, fonts, sizes, and positioning to match your application's design.

Last updated

Was this helpful?