FUIMarkerAnnotationView

@available(iOS 11.0, *)
open class FUIMarkerAnnotationView : MKMarkerAnnotationView

The FUIMapMarkerAnnotationView inherits from the MKMarkerAnnotationView and is presented as an annotation on the MKMapView. It is used to distinguish between location types and set a select priority to individual markers.

Note

We disabled setter of zPosition in order to prevent it from being modified when setting displayPriority. Set stickyZPosition instead.

## Available:

  • priorityIcon: a 17x17 icon image in the upper right corner of the marker. This can appear in both the selected and unselected state.

## Example Initialization and Configuration

 @available(iOS 11.0, *)
 class MyMarker: FUIMarkerAnnotationView {
     override var annotation: MKAnnotation? {
         willSet {
             markerTintColor = UIColor.preferredFioriColor(forStyle: .map1)
             glyphImage = FUIIconLibrary.map.marker.venue.withRenderingMode(.alwaysTemplate)
             displayPriority = .defaultLow
             priorityIcon =  FUIIconLibrary.map.marker.veryHighPriority
         }
     }
 }

Register within the viewDidLoad()

 if #available(iOS 11.0, *) {
    mapView.register(MyMarker.self, forAnnotationViewWithReuseIdentifier: MKMapViewDefaultAnnotationViewReuseIdentifier)
 } else {
    // Fallback on earlier versions
 }
 let point1 = MKPointAnnotation()
 point1.coordinate = CLLocationCoordinate2D(latitude: 37.3318, longitude: -122.0312)
 let point2 = MKPointAnnotation()
 point2.coordinate = CLLocationCoordinate2D(latitude: 37.3988313, longitude: -122.1487375)
 let annotations = [point1 as MKAnnotation, point2 as MKAnnotation]
 mapView.addAnnotations(annotations)

Set the annotation view in the mapView(_:viewFor:) method.

var view: MKAnnotationView!
if let pointAnnotation = annotation as? MKPointAnnotation {
    if #available(iOS 11.0, *) {
        view = FUIMarkerAnnotationView(annotation: pointAnnotation, reuseIdentifier: "cell")
        let annotationImage = FUIIconLibrary.map.marker.venue
        (view as! FUIMarkerAnnotationView).glyphImage = annotationImage.withRenderingMode(.alwaysTemplate)
        (view as! FUIMarkerAnnotationView).priorityIcon =  FUIIconLibrary.map.marker.veryHighPriority
    } else {
        // Fallback on earlier versions
        view = MKPinAnnotationView(annotation: pointAnnotation, reuseIdentifier: "cell")
    }
}
return view

## Note:

  • Set the glyphImage to a 20x20 icon.
  • An optional UIImage in the upper right corner of the marker. This can appear in both the unselected and selected states. Intended to distinguish an urgent marker vs a normal marker

    Declaration

    Swift

    public var priorityIcon: UIImage? { get set }
  • An initializer that instantiates a FUIMarkerAnnotationView with some reuseIdentifier. Sets the tint color to a default value of .map1

    Declaration

    Swift

    override public init(annotation: MKAnnotation?, reuseIdentifier: String?)
  • Restore all user-defined properties to default before resue.

    Declaration

    Swift

    open override func prepareForReuse()
  • A method that corrects the center of the priorityIconView based on the selected state.

    Declaration

    Swift

    override open func setSelected(_ selected: Bool, animated: Bool)

    Parameters

    selected

    a boolean value for selected (true) and unselected (false)

    animated

    a boolean value determining if the animation will occur

  • Override the layer factory for this class to return a custom CALayer class

    Declaration

    Swift

    override open class var layerClass: AnyClass { get }
  • Convenience accessor for setting zPosition

    Declaration

    Swift

    open var stickyZPosition: CGFloat { get set }