Browse building floors

View inMAUIWPFWinUIView on GitHub

Display and browse through building floors from a floor-aware web map.

BrowseBuildingFloorsApp

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 combo box to browse different floor levels in the facility. Only the selected floor will be displayed.

How it works

  1. Create a PortalItem using the identifier of a floor-aware web map.
  2. Create a map using the portal item.
  3. Create a map view and assign the map to it.
  4. Wait for the map to load and retrieve the map's FloorManager property.
  5. Wait for the floor manager to load and retrieve the floor-aware data.
  6. Set all floors to not visible.
  7. Select the ground floor by default. The ground floor is the entry in a facility's level collection that has VerticalOrder of zero. Vertical order can be negative for underground floors.
  8. Set the selected level's IsVisible property to true.
  9. When the selected floor changes, set the old selection's IsVisible property to false, and the new selection's IsVisible property to true.
  • Note: Manually set the default floor level to the first floor.

Relevant API

  • FloorAware
  • FloorLevel
  • FloorManager
  • Map
  • PortalItem

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 FloorManager API also supports browsing different sites and facilities in addition to building floors.

Tags

building, facility, floor, floor-aware, floors, ground floor, indoor, level, site, story

Sample Code

BrowseBuildingFloors.xaml.csBrowseBuildingFloors.xaml.csBrowseBuildingFloors.xaml
Use dark colors for code blocksCopy
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
// Copyright 2022 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.

using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Mapping.Floor;

namespace ArcGIS.Samples.BrowseBuildingFloors
{
    [ArcGIS.Samples.Shared.Attributes.Sample(
        name: "Browse building floors",
        category: "Map",
        description: "Display and browse through building floors from a floor-aware web map.",
        instructions: "Use the combo box to browse different floor levels in the facility. Only the selected floor will be displayed.",
        tags: new[] { "building", "facility", "floor", "floor-aware", "floors", "ground floor", "indoor", "level", "site", "story" })]
    public partial class BrowseBuildingFloors : ContentPage
    {
        private FloorManager _floorManager;

        // Collection of floors.
        private readonly Dictionary<string, FloorLevel> _floorOptions = new Dictionary<string, FloorLevel>();

        public BrowseBuildingFloors()
        {
            InitializeComponent();
            _ = Initialize();
        }

        private async Task Initialize()
        {
            try
            {
                // Gets the floor data from ArcGIS Online and creates a map with it.
                Map map = new Map(new Uri("https://ess.maps.arcgis.com/home/item.html?id=f133a698536f44c8884ad81f80b6cfc7"));

                MyMapView.Map = map;

                // Map needs to be loaded in order for floormanager to be used.
                await MyMapView.Map.LoadAsync();
                List<string> floorName = new List<string>();

                // Checks to see if the layer is floor aware.
                if (MyMapView.Map.FloorDefinition == null)
                {
                    await Application.Current.MainPage.DisplayAlert("Alert", "The layer is not floor aware.", "OK");
                    return;
                }

                await MyMapView.Map.FloorManager.LoadAsync();
                _floorManager = MyMapView.Map.FloorManager;

                // Use the dictionary to add the level's name as the key and the FloorLevel object with the associated level's name.
                foreach (FloorLevel level in _floorManager.Facilities[0].Levels)
                {
                    _floorOptions.Add(level.ShortName, level);
                    floorName.Add(level.ShortName);
                }

                FloorChooser.ItemsSource = floorName;
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Alert", ex.Message, "OK");
            }
        }

        private void OnFloorChooserSelectionChanged(object sender, EventArgs e)
        {
            // Get the name of the selected floor.
            string selectedFloorName = FloorChooser.SelectedItem.ToString();

            // Set all existing floors visibility to false.
            foreach (FloorLevel level in _floorManager.Levels)
            {
                level.IsVisible = false;
            }

            // Set the selected floor visibility to true.
            _floorOptions[selectedFloorName].IsVisible = true;

            MyMapView.SetViewpoint(new Viewpoint(_floorOptions[selectedFloorName].Facility.Geometry));
        }
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.