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.
Step 4: Initialize MapsIndoors and CustomFloorSelector
Now, let's initialize MapsIndoors and our custom floor selector:
//Previous code from Getting Started Guide// Initialize CustomFloorSelectorconstcustomFloorSelector=newCustomFloorSelector(mapsIndoorsInstance);document.body.appendChild(customFloorSelector.element);
Step 5: Set Up Event Listeners
Finally, set up event listeners to update the floor selector when necessary:
// Set up event listeners for MapsIndoorsmapsIndoorsInstance.addListener('ready', () => {customFloorSelector.onShow();customFloorSelector.updateWithCurrentBuilding();});mapsIndoorsInstance.addListener('floor_changed', () => {customFloorSelector.updateFloorButtons();});mapsIndoorsInstance.addListener('building_changed', () => {customFloorSelector.updateWithCurrentBuilding();});// Log any MapsIndoors errorsmapsIndoorsInstance.addListener('error', (error) => {console.error("MapsIndoors error:", error);});
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.