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 dropdown menu 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.
  5. Wait for the floor manager to load and get its list of FloorLevels.
  6. Set the isVisible property to false for all floor levels.
  7. Set only the selected FloorLevel to visible using the isVisible property of the floor level.
  • Note: Manually set the default floor level to the first floor.

Relevant API

  • FloorLevel
  • FloorManager

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.cpp BrowseBuildingFloors.cpp BrowseBuildingFloors.h BrowseBuildingFloors.qml main.cpp main.qml
// [WriteFile Name=BrowseBuildingFloors, Category=Maps]
// [Legal]
// 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.
// [Legal]
#ifdef PCH_BUILD
#include "pch.hpp"
#endif // PCH_BUILD
// sample headers
#include "BrowseBuildingFloors.h"
// ArcGIS Maps SDK headers
#include "Error.h"
#include "FloorLevel.h"
#include "FloorManager.h"
#include "Map.h"
#include "MapQuickView.h"
#include "MapTypes.h"
#include "Portal.h"
#include "PortalItem.h"
using namespace Esri::ArcGISRuntime;
BrowseBuildingFloors::BrowseBuildingFloors(QObject* parent /* = nullptr */):
QObject(parent)
{
Portal* portal = new Portal(QUrl("https://www.arcgis.com/"), this);
PortalItem* portalItem = new PortalItem(portal, "f133a698536f44c8884ad81f80b6cfc7", this);
// Create a map object using the portalItem
m_map = new Map(portalItem, this);
connect(m_map, &Map::doneLoading, this, [this]()
{
if (m_map->loadStatus() == LoadStatus::Loaded)
{
m_floorManager = m_map->floorManager();
}
connect(m_floorManager, &FloorManager::doneLoading, this, [this]()
{
if (m_floorManager && m_floorManager->loadStatus() == LoadStatus::Loaded)
{
for (FloorLevel* level : m_floorManager->levels())
{
level->setVisible(false);
}
// Manually set the default floor level to the first floor
m_floorManager->levels().at(0)->setVisible(true);
}
});
m_floorManager->load();
});
}
BrowseBuildingFloors::~BrowseBuildingFloors() = default;
void BrowseBuildingFloors::init()
{
// Register the map view for QML
qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView");
qmlRegisterType<BrowseBuildingFloors>("Esri.Samples", 1, 0, "BrowseBuildingFloorsSample");
}
MapQuickView* BrowseBuildingFloors::mapView() const
{
return m_mapView;
}
// Set the view (created in QML)
void BrowseBuildingFloors::setMapView(MapQuickView* mapView)
{
if (!mapView || mapView == m_mapView)
return;
m_mapView = mapView;
m_mapView->setMap(m_map);
emit mapViewChanged();
}
void BrowseBuildingFloors::selectFloor(const QString& floor_number)
{
if (m_floorManager && m_floorManager->loadStatus() == LoadStatus::Loaded)
{
if (floor_number.compare("Level 1") == 0)
{
m_floorManager->levels().at(0)->setVisible(true);
//Make the other floors invisible
m_floorManager->levels().at(1)->setVisible(false);
m_floorManager->levels().at(2)->setVisible(false);
}
if (floor_number.compare("Level 2") == 0)
{
m_floorManager->levels().at(1)->setVisible(true);
//Make the other floors invisible
m_floorManager->levels().at(0)->setVisible(false);
m_floorManager->levels().at(2)->setVisible(false);
}
if (floor_number.compare("Level 3") == 0)
{
m_floorManager->levels().at(2)->setVisible(true);
//Make the other floors invisible
m_floorManager->levels().at(0)->setVisible(false);
m_floorManager->levels().at(1)->setVisible(false);
}
}
}