View on GitHub
Sample viewer app
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 spinner to browse different floor levels in the facility. Only the selected floor will be displayed.
How it works
Create a PortalItem
using the itemId
of the floor-aware web map.
Set the MapView
to display the PortalItem
.
Wait for the map to load and retrieve the map's floor manager from MapView.Map.FloorManager
. Then run FloorManager.loadAsync()
.
Wait for the floor manager to load using FloorManager.addDoneLoadingListener
to retrieve the floor-aware data.
Set all floors to not visible FloorManager.levels[floor-number].isVisible = false
.
Set only the selected floor to visible using FloorManager.levels[floor-number].isVisible = true
.
Note: Manually set the default floor level to the first floor.
Relevant API
About the data
This sample uses a floor-aware web map that displays the floors of Building L on the Esri Redlands campus.
The API also supports browsing different sites and facilities in addition to building floors.
building, facility, floor, floor-aware, floors, ground floor, indoor, level, site, story
Sample CodeMainActivity.kt CopyUse dark colors for code blocks
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
146
147
148
149
/* 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
*
* http://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.
*
*/
package com.esri.arcgisruntime.sample.browsebuildingfloors
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.Spinner
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.esri.arcgisruntime.loadable.LoadStatus
import com.esri.arcgisruntime.mapping.ArcGISMap
import com.esri.arcgisruntime.mapping.floor.FloorManager
import com.esri.arcgisruntime.mapping.view.MapView
import com.esri.arcgisruntime.portal.Portal
import com.esri.arcgisruntime.portal.PortalItem
import com.esri.arcgisruntime.sample.browsebuildingfloors.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity () {
private val TAG: String = MainActivity:: class .java.simpleName
private val activityMainBinding by lazy {
ActivityMainBinding.inflate(layoutInflater)
}
private val mapView: MapView by lazy {
activityMainBinding.mapView
}
private val levelSpinner: Spinner by lazy {
activityMainBinding.levelSpinner
}
// keep track of the current selected floor
private var currentFloor = 0
override fun onCreate (savedInstanceState: Bundle ?) {
super .onCreate(savedInstanceState)
setContentView(activityMainBinding.root)
// load the portal and create a map from the portal item
val portal = Portal( "https://www.arcgis.com/" , false )
val portalItem = PortalItem(portal, "f133a698536f44c8884ad81f80b6cfc7" )
val map = ArcGISMap(portalItem)
// set the map to be displayed in the layout's MapView
mapView.map = map
map.addDoneLoadingListener {
if (map.loadStatus == LoadStatus.LOADED && map.floorDefinition != null ) {
// get and load the floor manager
val floorManager = map.floorManager
floorManager.loadAsync()
// set initial floor level to currentFloor
setFloor(floorManager)
levelSpinner.onItemSelectedListener =
object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected (parent: AdapterView <*>?) {
// do nothing here
}
override fun onItemSelected (
parent: AdapterView <*>,
view: View ?,
position: Int ,
id: Long
) {
// update and set the map to the selected floor
currentFloor = position
setFloor(floorManager)
}
}
} else {
val error = "Error loading map or map is not floor-aware"
Toast.makeText( this , error, Toast.LENGTH_LONG).show()
Log.e(TAG, error)
}
}
// set the spinner adapter for the floor selection
levelSpinner.adapter = ArrayAdapter.createFromResource(
this ,
R.array.floors,
android.R.layout.simple_spinner_item
).apply {
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
}
}
/**
* update the [floorManager] to the currently selected floor
* and disable the other floors.
*/
private fun setFloor (floorManager: FloorManager ) {
floorManager.addDoneLoadingListener {
if (floorManager.loadStatus == LoadStatus.LOADED) {
// set all the floors to invisible to reset the floorManager
floorManager.levels.forEach { floorLevel ->
floorLevel.isVisible = false
}
// set the currently selected floor to be visible
floorManager.levels[currentFloor].isVisible = true
} else {
val error = "Error loading floor manager: " + floorManager.loadError.message
Log.e(TAG, error)
Toast.makeText( this , error, Toast.LENGTH_LONG).show()
}
}
}
override fun onPause () {
mapView.pause()
super .onPause()
}
override fun onResume () {
super .onResume()
// update the spinner to the currently selected floor
levelSpinner.setSelection(currentFloor)
mapView.resume()
}
override fun onDestroy () {
mapView.dispose()
super .onDestroy()
}
}