Skip to main content
Version: 6.0

Building & Floor Selection

Using Mappedin SDK for iOS with your own map requires a Pro license. Try a demo map for free or refer to the Pricing page for more information.

Floor Selection

When mapping a building with multiple floors, each floor has its own unique map. These are represented by the Floor class, which are accessed using MapData.getByType(). The currently displayed Floor can be accessed using MapView.currentFloor.

tip

A complete example demonstrating Building and Floor Selection can be found in the Mappedin iOS Github repo: BuildingFloorSelectionDemoViewController.kt

Changing Floors

When initialized, MapView displays the Floor with the elevation that's closest to 0. This can be overridden by setting Show3DMapOptions.initialFloor to a Floor.id and passing it to MapView.show3dMap().

// Setting the initial floor to Floor.id 'm_123456789'.
self.mapView.show3dMap(options: Show3DMapOptions(initialFloor: "m_123456789")) { r2 in
if case .success = r2 {
// Successfully initialized the map view.
} else if case .failure(let error) = r2 {
// Failed to initialize the map view.
}
}

The Floor displayed in a MapView can also be changed during runtime by calling MapView.setFloor() and passing in a Floor.id.

// Set the floor to Floor.id 'm_987654321'.
mapView.setFloor(floorId: "m_987654321") { result in
switch result {
case .success:
print("Floor changed successfully")
case .failure(let error):
print("Error: \(error)")
}
}

Listening for Floor Changes

Mappedin SDK for iOS provides the ability to listen for floor changes on a MapView. The code below listens for the floor-change event and logs the new floor and building name to the console.

mapView.on(Events.floorChange) { [weak self] data in
guard let self = self else { return }
if let payload = data as? FloorChangePayload {
print("Floor changed to: \(payload.floor.name) in building: \(payload.floor.floorStack?.name ?? "unknown")")
}
}

Building Selection

Mappedin Maps can contain one to many buildings with each building having one to many floors. Each building has its floors organized into a FloorStack object. When multiple buildings are present, there are multiple FloorStack objects, one for each building. A FloorStack contains one to many Floor objects, each representing the map of each level of the building.

The FloorStack object is accessed by using MapData.getByType().

// Get all floor stacks
mapView.mapData.getByType(.floorStack) { [weak self] (result: Result<[FloorStack], Error>) in
guard let self = self else { return }
if case .success(let stacks) = result {
self.floorStacks = stacks.sorted { $0.name.localizedCompare($1.name) == .orderedAscending }

// Get all floors in the floor stack
self.mapView.mapData.getByType(.floor) { [weak self] (floorsResult: Result<[Floor], Error>) in
guard let self = self else { return }
if case .success(let floors) = floorsResult {
print("Floors: \(floors)")
}
}
}
}
tip

A complete example demonstrating Building and Floor Selection can be found in the Mappedin iOS Github repo: BuildingFloorSelectionDemoViewController.kt