Skip to main content

Floor plans

Floor plans are available for selected buildings and are shown on style zoom level 18 and above.

Events

When a floor plan is displayed, it triggers the floorplanshow event (see FloorPlanShowEvent for the event object). Similarly, when a floor plan is hidden, it triggers the floorplanhide event (see FloorPlanHideEvent).

Additionally, when the floor number is changed (using FloorControl or the setFloorPlanLevel() method), the floorlevelchange event is triggered (see FloorLevelChangeEvent).

To subscribe to these events, use the on() method.

map.on('floorplanshow', (e) => {
alert(`Floor plan ${e.floorPlanId} is shown.`);
});
map.on('floorplanhide', (e) => {
alert(`Floor plan ${e.floorPlanId} is hidden.`);
});
map.on('floorlevelchange', (e) => {
alert('Floor number is changed.');
});

Change floor number

To change the floor number, call the setFloorPlanLevel() method and specify two parameters: the ID of the floor plan and the floor index. You can get the floor index as well as the floor plan ID, for example, by subscribing to FloorPlanShowEvent.

The example below changes the map behavior to initially show the last floor of the building by getting the index of the last floor and passing it to setFloorPlanLevel().

map.on('floorplanshow', (e) => {
const length = e.floorLevels.length;
const { floorLevelIndex } = e.floorLevels[length - 1];
map.setFloorPlanLevel(e.floorPlanId, floorLevelIndex);
});