Display and browse through building floors from a floor-aware web map.
Use case
Having map data to aid indoor navigation in buildings with multiple floors such as airports, museums, or offices can be incredibly useful. For example, you may wish to browse through all available floor maps for an office in order to find the location of an upcoming meeting in advance.
How to use the sample
Use the picker to browse different floor levels in the facility. Only the selected floor will be displayed.
How it works
Create and load a floor-aware web map using the identifier of an AGSPortalItem.
Load the map and retrieve the map's floorManager property. Check that the map has a floorManager or floorDefinition property to ensure the map is floor-aware.
Load the floor manager and retrieve the floor-aware data.
Set the current visible floor to the first floor by finding the AGSFloorLevel whose verticalOrder property equals zero.
When an AGSFloorLevel is selected, set only the selected floor level to visible using the isVisible property.
Relevant API
AGSFloorLevel
AGSFloorManager
About the data
This sample uses a floor-aware web map that displays the floors of Building L on the Esri Redlands campus.
Additional information
The AGSFloorManager API also supports browsing different sites and facilities in addition to building floors.
Floor-awareness APIs support both maps and scenes. To learn more about floor-aware maps, read the Configure floor-aware maps article.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2021 Esri//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at//// https://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.import UIKit
import ArcGIS
classBrowseBuildingFloorsViewController: UIViewController{
// MARK: Storyboard views/// The map view managed by the view controller.@IBOutletvar mapView: AGSMapView! {
didSet {
mapView.map = makeMap()
}
}
/// The floor level picker view.@IBOutletvar floorLevelPickerView: UIPickerView!
// MARK: Properties/// The floor levels of the floor-aware web map.var floorLevels: [AGSFloorLevel] = []
/// The currently selected floor level.var selectedFloorLevel: AGSFloorLevel? {
didSet {
// Set the selected level to visible and the previous to invisible. oldValue?.isVisible =false selectedFloorLevel?.isVisible =true// Update picker view selection.let row: Intiflet selectedFloorLevel = selectedFloorLevel {
row = floorLevels.firstIndex(of: selectedFloorLevel)!+1 } else {
row = .zero
}
floorLevelPickerView.selectRow(row, inComponent: 0, animated: true)
}
}
// MARK: MethodsfuncsetPickerViewLayout() {
floorLevelPickerView.translatesAutoresizingMaskIntoConstraints =false floorLevelPickerView.layer.cornerRadius =10.0NSLayoutConstraint.activate([
floorLevelPickerView.widthAnchor.constraint(equalToConstant: 120.0),
view.safeAreaLayoutGuide.trailingAnchor.constraint(equalToSystemSpacingAfter: floorLevelPickerView.trailingAnchor, multiplier: 1),
mapView.attributionTopAnchor.constraint(equalToSystemSpacingBelow: floorLevelPickerView.bottomAnchor, multiplier: 1)
])
}
/// Create a map.funcmakeMap() -> AGSMap {
// A floor-aware web map for floors of Esri Building L in Redlands.let map =AGSMap(item: AGSPortalItem(
portal: .arcGISOnline(withLoginRequired: false),
itemID: "f133a698536f44c8884ad81f80b6cfc7" ))
map.load { [weakself] error iniflet error = error {
self?.presentAlert(error: error)
} else {
self?.mapDidLoad(map)
}
}
return map
}
/// Called after the web map is loaded without error.funcmapDidLoad(_map: AGSMap) {
// The floor manager of the web map, which exposes the sites,// facilities, and levels of the floor-aware data model.guardlet floorManager = map.floorManager else { return }
floorManager.load { [weakself] error iniflet error = error {
self?.presentAlert(error: error)
} else {
self?.floodManagerDidLoad(floorManager)
}
}
}
/// Called after the floor manager of the web map is loaded without error.funcfloodManagerDidLoad(_floorManager: AGSFloorManager) {
guardlet geometry = floorManager.sites.first?.geometry,
// Select the ground floor using `verticalOrder`.// In the case of buildings with basements, they can have negative// vertical orders; ground floor is expected to be 0.// You can also use level ID, number or name to locate a floor.let firstFloor = floorManager.levels.first(where: { $0.verticalOrder ==0 }) else { return }
mapView.setViewpointGeometry(geometry)
// Update floor levels and select the first floor. floorLevels = floorManager.levels
floorLevelPickerView.reloadAllComponents()
selectedFloorLevel = firstFloor
}
// MARK: UIViewControlleroverridefuncviewDidLoad() {
super.viewDidLoad()
// Add the source code button item to the right of navigation bar. (navigationItem.rightBarButtonItem as?SourceCodeBarButtonItem)?.filenames = ["BrowseBuildingFloorsViewController"]
// Set the appearance of the floor level picker view. setPickerViewLayout()
}
}
// MARK: - UIPickerViewDataSourceextensionBrowseBuildingFloorsViewController: UIPickerViewDataSource{
funcnumberOfComponents(inpickerView: UIPickerView) -> Int {
1 }
funcpickerView(_pickerView: UIPickerView, numberOfRowsInComponentcomponent: Int) -> Int {
floorLevels.count +1 }
}
// MARK: - UIPickerViewDelegateextensionBrowseBuildingFloorsViewController: UIPickerViewDelegate{
funcpickerView(_pickerView: UIPickerView, titleForRowrow: Int, forComponentcomponent: Int) -> String? {
let index = row -1return index >= floorLevels.startIndex ? floorLevels[index].shortName : "None" }
funcpickerView(_pickerView: UIPickerView, didSelectRowrow: Int, inComponentcomponent: Int) {
let index = row -1 selectedFloorLevel = index >= floorLevels.startIndex ? floorLevels[index] : nil }
}