LogoLogo
CMSGitHubSupportBook a demo
  • Documentation
  • Academy
  • Help Center
  • Welcome
  • SDKS & Frameworks
    • Web
      • Getting Started
        • Prerequisites
          • MapsIndoors
          • Map Engine Provider
            • Option 1: Get your Mapbox Access Token
            • Option 2: Get your Google Maps API Keys​
          • Map Engine Setup
        • Getting Started: MapsIndoors
      • Map Visualization
        • Highlight, Hover and Select
        • Remove Labels from Buildings and Venues
        • Change Building Outline
        • Managing Collisions Based on Zoom Level
        • 3D Maps
          • Managing your 3D Maps
        • Base Map Styling - Google Maps
        • Managing feature visibility for Mapbox
      • Wayfinding
        • Directions
        • Directions Service
          • Tailoring the directions to your specific needs
        • Directions Renderer
          • Customizing the Route Animation
        • Multi-stop navigation
          • Custom Icons
        • User's Location as Point of Origin
      • Search
        • Search Operations
        • Searching
        • Using External ID, Geospatial Joins
        • Utilizing MapsIndoors Web Components and Other Searches
      • Map Management
      • Data Visualization
        • Display Heatmap Overlay
      • Other guides
        • Authentication
          • Single Sign-On
            • SSO Configuration
            • SSO Authorisation
          • 2-Factor Authentication
          • Password Reset
        • Application User Roles
        • Custom Properties
        • Display Language
        • Language
        • User Positioning
          • Show User's Location aka. Blue Dot
          • Using Cisco DNA Spaces
        • Working with Events
        • Turn Off Collisions Based on Zoom Level
        • Remove Labels from Buildings and Venues for Web
        • Synchronizing data for a subset of venues
        • Custom Floor Selector
      • Display Rules in Practice
      • Offline Data
      • Managing map visibility
    • Android
      • Getting Started
        • Prerequisites
        • Create a New Project
        • Show a Map
        • Create a Search Experience
        • Getting Directions
        • Enable Live Data
        • Integrating MapsIndoors into your own App
        • Migrating from V3 to V4
          • Migrating to Mapbox V11
      • Directions
        • Directions Service
        • Directions Renderer
          • User's Location as Point of Origin
        • Wayfinding Instructions
          • See Route Element Details
        • Using multi-stop navigation
      • Searching
        • Searching on a Map
        • Creating a Search Experience
      • Switching Solutions
      • Caching & Offline Data
      • Display Language
      • Displaying Objects
        • Application User Roles
        • Getting a Polygon from a Location
        • Location Clustering
        • Location Data Sources
        • Location Details
        • Turn Off Collisions Based on Zoom Level
        • Enabling and Disabling features on the map
      • Change Building Outline Color
      • Event Logging
      • Configuring a menu with AppConfig
      • Display Heatmap Overlay
      • Custom Properties
      • Custom Floor Selector
      • External IDs
      • User Positioning
        • Show User's Location aka. Blue Dot
        • Using Cisco DNA Spaces
        • Using Google Fused Location Provider
        • Using Indoor Atlas
      • Authentication
        • Single Sign-On
          • SSO Configuration
          • SSO Authorisation
        • 2-Factor Authentication
        • Password Reset
      • Display Rules in Practice
        • Label styling through Display Rules
      • Highlight and Select
    • iOS
      • Getting Started
        • Prerequisites
        • Set Up Your Environment
        • Display a Map
        • Search
        • Getting Directions
        • Migrating from v3 to v4
      • Directions
        • Directions Renderer
          • User's Location as Point of Origin
        • Wayfinding Instructions
          • See Route Element Details
        • Directions Service
        • Using multi-stop navigation
      • Searching
        • Searching on a Map
        • Creating a Search Experience
      • Caching & Offline Data
      • Displaying Objects
        • Application User Roles
        • Getting a Polygon from a Location
        • Location Details
        • Turn Off Collisions Based on Zoom Level
        • Enabling and Disabling features on the map
      • Custom Floor Selector
      • Change Building Outline Color
      • Custom Map Padding
      • Custom Properties
      • Display Rules in Practice
        • Label styling through Display Rules
      • Switching Solutions
      • Show User's Location aka. Blue Dot
        • Using Indoor Atlas
        • Using Cisco DNA Spaces
      • Highlight and Select
      • Display Language
    • React Native
      • Getting Started
        • Prerequisites
        • Project Setup
        • Displaying a Map
        • Creating a Search Experience
        • Getting Directions
        • Enabling Live Data
      • Showing Blue Dot
    • Flutter
      • Getting Started
        • Prerequisites
        • Create a New Project
        • Show a Map
        • Create a Search Experience
        • Getting Directions
      • Migration Guide
    • Integration API
      • Integration API Access
        • Access with Swagger
        • Access with Postman
        • Access with Python
        • Client credentials flow
      • Data Description
      • Reverse Geocoding
      • Route Access
      • OpenAPI Specification
    • Built-In Map Edits
      • Getting started
      • Authentication
      • Release notes
      • Reference docs
  • Products
    • Product Overview
    • CMS
      • Interface Overview
      • Display Rules
      • Media Library
        • 2D Models and Icons
        • 3D Models
      • Editing Data
      • Solution Settings
      • Settings
      • Data Concepts
      • User Roles
      • Route Network
        • Barrier Route Element
        • Door Route Element
      • Additional Location Details
    • Map Template
      • Getting Started
        • Web Component
        • React Component
      • Configuration
        • Query Parameters
      • Customization
      • Deploying Map Template to a cloud storage provider
      • 2D/3D Visibility Switch
      • External customization of the Map Template
      • Location Details configuration
      • Kiosk
        • QR code configuration
  • Other
    • Design
      • Standard MapsIndoors Map Style
      • Using a Custom Mapbox MapStyle
    • Changelog
      • Web SDK
        • V4
        • V3
      • Android SDK
        • V4
        • V3
      • iOS SDK
        • V4
        • V3
      • React Native SDK
      • Flutter SDK
      • MI Components
      • Map Template
    • Glossary
  • Legacy Docs
    • Android SDK V3
      • Getting Started
        • Prerequisites
        • Create a New Project
        • Show a Map
        • Create a Search Experience
        • Getting Directions
        • Enable Live Data
        • Integrating MapsIndoors into your own App
    • iOS SDK V3
      • Getting Started
        • Prerequisites
        • Set Up Your Environment
        • Display a Map
        • Search
        • Directions
        • Live Data
        • Integrating MapsIndoors into your own App
      • Inspect Route Element for iOS v3
      • Using Cisco DNA Spaces
      • Using Indoor Atlas
      • Switching Solutions
      • Show User's Location aka. Blue Dot
      • Application User Roles
      • Getting a Polygon from a Location
      • Location Details
  • MapsIndoors SDK Firewall
  • Google Analytics & Logging
  • Reference Docs
    • Web SDK
    • Android SDK
    • iOS SDK
    • React Native SDK
    • Flutter SDK
Powered by GitBook
On this page
  • How to implement a custom floor selector​
  • Expected Result

Was this helpful?

Export as PDF
  1. SDKS & Frameworks
  2. iOS

Custom Floor Selector

Last updated 7 months ago

Was this helpful?

How to implement a custom floor selector

To get started, create a class that conforms to both MPCustomFloorSelector and UIView. Please bear in mind that the provided example is solely for illustrative purposes. It is essential to appropriately integrate and customize it to align with your specific requirements and design preferences.

// Custom Floor Selector class that conforms to both UIView and MPCustomFloorSelector
class MyFloorSelector: UIView, MPCustomFloorSelector {
    override init(frame: CGRect) {
        super.init(frame: frame)
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }

    func remove() {
        removeFromSuperview()
    }

    var building: MapsIndoors.MPBuilding? {
        didSet {
            if building?.administrativeId != oldValue?.administrativeId {
                createFloorButtons()
                updateCurrentFloorButton()
            }
        }
    }

    var delegate: MapsIndoors.MPFloorSelectorDelegate?
    var floorIndex: NSNumber? {
        didSet {
            updateCurrentFloorButton()
        }
    }

    func onShow() {
        // Shows the floor selector
        isHidden = false
    }

    func onHide() {
        // Hides the floor selector
        isHidden = true
    }

    func createFloorButtons() {
        // Remove existing buttons
        for button in floorButtons {
            button.removeFromSuperview()
        }
        floorButtons.removeAll()

        guard let floors = building?.floors else { return }

        let buttonHeight: CGFloat = 50
        let buttonWidth: CGFloat = 50 // Increased width
        var yOffset: CGFloat = 0
        let xOffset: CGFloat = 20 // Offset from the left of the screen

        // Sort the floors by their floorIndex
        let sortedFloors = floors.sorted { $0.value.floorIndex?.intValue ?? 0 < $1.value.floorIndex?.intValue ?? 0 }

        for (_, floor) in sortedFloors {
            let floorButton = UIButton(frame: CGRect(x: xOffset, y: yOffset, width: buttonWidth, height: buttonHeight))
            floorButton.backgroundColor = .cyan
            floorButton.setTitle(floor.name, for: .normal) // Set the button title to the floor name
            floorButton.addTarget(self, action: #selector(floorButtonTapped), for: .touchUpInside)
            addSubview(floorButton)
            floorButtons.append(floorButton)
            yOffset += buttonHeight
        }
    }

    @objc func floorButtonTapped(sender: UIButton!) {
        guard let floorName = sender.title(for: .normal),
              let floor = building?.floors?.first(where: { $0.value.name == floorName }), // Find the floor using the floor name
              let floorIndex = floor.value.floorIndex else { return }

        // Update the floor index
        self.floorIndex = floorIndex

        // Notify the delegate
        delegate?.onFloorIndexChanged(floorIndex)
    }

    func updateCurrentFloorButton() {
        // Reset the color of the previous current floor button
        currentFloorButton?.backgroundColor = .cyan

        // Find the button corresponding to the current floor using the floor name
        currentFloorButton = floorButtons.first(where: { $0.title(for: .normal) == building?.floors?.first(where: { $0.value.floorIndex == floorIndex })?.value.name })

        // Change the color of the current floor button
        currentFloorButton?.backgroundColor = .blue
    }
}

Next step is to initialize and add the class to MPMapControl.

// Initialize a custom floor selector with a CGRect
customFloorSelector = MyFloorSelector(frame: CGRect(x: 40, y: 150, width: floorSelectorWidth, height: floorSelectorHeight))

// Set the mapControl´s floorSelector to your newly created floorSelector
mapControl?.floorSelector = customFloorSelector

When configuring the floor selector class MyFloorSelector, it is necessary to align the x and y coordinates according to your specific requirements. Utilizing constraints to ensure compatibility across various devices is highly recommended.

Next step is to handle the floor index. In this example, the floor selector requires knowledge of the current floor index, which can be obtained by reading the value from the current building.

floorIndex = mapControl?.currentBuilding?.currentFloor

It is important that the class representing the custom floor selector you have developed must conform to both the UIView and MPCustomFloorSelector protocols.

Expected Result

​