FUIMapLegend

open class FUIMapLegend : FUIResizablePopoverContainer
extension FUIMapLegend: UIViewControllerTransitioningDelegate
extension FUIMapLegend: UITableViewDelegate
extension FUIMapLegend: UITableViewDataSource

FUIMapLegend extends UIViewController to show the Map Legend.

FUIMapLegend is presented in a UIPopoverView on iPad and presented in a UIPresentationController on iPhone

Available in FUIMapLegend:

  • headerTextView: a TextView intended to display a footnote text.
  • passThroughViews: an array of UIView that a user can interact with while popover is visible

Example Initialization and Configuration:

In view controller’s viewDidLoad method:


let toolbar = FUIMapToolbar(mapView: mapView)
let legend = FUIMapLegend()
legend.toolbarButton = FUIMapToolbarLegendButton()
legend.headerTextView.text = "MapView Example Legend"
legend.passThroughViews = [toolbar, mapView]

var venueItem = FUIMapLegendItem(title: "Self Service")
venueItem.backgroundColor = UIColor.preferredFioriColor(forStyle: .map1)
let venueImage = FUIAttributedImage(image: FUIIconLibrary.map.marker.venue.withRenderingMode(.alwaysTemplate))
venueImage.tintColor = .white
venueItem.icon = FUIMapLegendIcon(glyphImage: venueImage)

var valetItem = FUIMapLegendItem(title: "Valet")
valetItem.backgroundColor = UIColor.preferredFioriColor(forStyle: .map2)
let valetImage =  FUIAttributedImage(image: FUIIconLibrary.map.marker.walk.withRenderingMode(.alwaysTemplate))
valetImage.tintColor = .white
valetItem.icon = FUIMapLegendIcon(glyphImage: valetImage)
valetItem.line = FUIMapLegendLine(dashPattern: [10,8], dashPhase: 3.0)

let highActivityRegion = FUIMapLegendFillItem()
highActivityRegion.fillColor = UIColor.preferredFioriColor(forStyle: .map3)
highActivityRegion.borderColor = UIColor.preferredFioriColor(forStyle: .map3)
var highActivityRegionItem = FUIMapLegendItem(title: "High Activity Region")
highActivityRegionItem.fillItem = highActivityRegion

var highTrafficPathItem = FUIMapLegendItem(title: "High Traffic Path")
highTrafficPathItem.backgroundColor = UIColor.preferredFioriColor(forStyle: .map4)
highTrafficPathItem.line = FUIMapLegendLine(dashPattern: [2,2], dashPhase: 0.0)

legend.items = [highActivityRegionItem, valetItem, venueItem, highTrafficPathItem]

let legendHandler: ((FUIButton) -> Void)? = { [weak self] button in
    DispatchQueue.main.async {

        var dismissLegendAndRestoreCachedController = { [unowned self, unowned button] in
           self.dismiss(animated: true, completion: {
           button.isSelected = false
           })
        }

        let presentNewLegendPhone = {
           self.present(legend, animated: true, completion: nil)
        }

        let presentNewLegendPad = {
           legend.setupPopoverAttributes(popOver: legend.popoverPresentationController!, sender: button)
           if self.presentedViewController == nil {
               self.present(legend, animated: false, completion: nil)
           }
        }

        guard button.isSelected else {
           dismissLegendAndRestoreCachedController()
           return
        }

        let presentNewClosure = UIDevice.current.userInterfaceIdiom == .phone ? presentNewLegendPhone : presentNewLegendPad

        guard let presentedController = UIDevice.current.userInterfaceIdiom == .phone ? self.presentedViewController : self.popoverPresentationController?.presentedViewController else {
           presentNewClosure()
           return
        }

        if presentedController == legend {
           dismissLegendAndRestoreCachedController()
        } else {
           self.dismiss(animated: true, completion: {
               presentNewClosure()
           })
        }
    }
}
legend.toolbarButton?.didSelectHandler = legendHandler
let locationButton = FUIMapToolbarUserLocationButton(mapView: self.mapView)
toolbar.items = [legend.toolbarButton!, locationButton]

theming

fdlFUIMapLegendContainer_headerTextView {
font-color: @primary3;
font-name: semiboldSystem;
font-style: footnote;
}

notes

See

See implementation of FUIMapLegend using a FUIMapToolbarLegendButton for a complete implementation.
  • An array of UIView that a user can interact with while popover is visible.

    Note

    • only applied in iPad Variant

    Declaration

    Swift

    public var passThroughViews: [UIView]
  • A reference to the FUIMapToolbarLegendButton in order to call the cancelButtonHandler

    Declaration

    Swift

    public var toolbarButton: FUIMapToolbar.LegendButton?
  • A UITextView that displays the Map Legend Title. Set the title within the Text View by calling its .text setter.

    Declaration

    Swift

    public var headerTextView: UITextView!
  • Adjusts the bottom Anchor to the safeArea.

    Declaration

    Swift

    open override func viewWillLayoutSubviews()
  • Determines for preferredContentSize for view. Sets tableWidth according to device platform. Preferred height is the sum of tableView height, headerTextView height, and divider height

    Declaration

    Swift

    override open var preferredContentSize: CGSize { get set }
  • A method to set correct arrow source view and direction.

    Note

    • only applied in iPad Variant

    Declaration

    Swift

    public func setupPopoverAttributes(popOver popController: UIPopoverPresentationController, sender view: UIView)

    Parameters

    popOver

    A UIPopoverPresentationController to be presented

    sender

    A UIView to determine popover arrow size.

  • Presents the presentation controller as a FUIPartialSizePresentationController only covering a portion of the screen on iPhone

    Declaration

    Swift

    open func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController?
  • Animates the sliding direction during presentation.

    Declaration

    Swift

    open func animationController(forPresented presented: UIViewController,
                                  presenting: UIViewController,
                                  source: UIViewController) -> UIViewControllerAnimatedTransitioning?
  • Animates the sliding direction during dismissal.

    Declaration

    Swift

    open func animationController(forDismissed dismissed: UIViewController)
        -> UIViewControllerAnimatedTransitioning?
  • FUIMapLegend presents a single section`

    Declaration

    Swift

    open func numberOfSections(in tableView: UITableView) -> Int
  • FUIMapLegend presents the number of rows of FUIMapLegendItem

    Declaration

    Swift

    open func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
  • FUIMapLegend dequeues a FUIMapLegendItemTableViewCell to present the FUIMapLegendItem

    Declaration

    Swift

    open func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell