FUIProfileMarkerAnnotationView

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

The FUIProfileMarkerAnnotationView inherits from the MKMarkerAnnotationView and is presented as an annotation on the MKMapView. It is used to distinguish between static points on a map and person location. The annotation can either display a profilePicture or a set of initials to represent the person being annotated.

Example Initialization and Configuration

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

Register within the viewDidLoad()

if #available(iOS 11.0, *) {
   mapView.register(MyProfileMarker.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)
mapView.showAnnotations(annotations, animated: true)

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

var view: MKAnnotationView!
if let pointAnnotation = annotation as? MKPointAnnotation {
   if #available(iOS 11.0, *) {
       if pointAnnotation.coordinate.latitude == 37.3318 {
           view = FUIProfileMarkerAnnotationView(annotation: pointAnnotation, reuseIdentifier: "cell")
           (view as! FUIProfileMarkerAnnotationView).glyphText =  "ME"
           return view
       } else {
           view = FUIProfileMarkerAnnotationView(annotation: pointAnnotation, reuseIdentifier: "cell")
           (view as! FUIProfileMarkerAnnotationView).glyphImage = #imageLiteral(resourceName: "ProfilePic").withRenderingMode(.alwaysOriginal)
           (view as! FUIProfileMarkerAnnotationView).selectedGlyphImage = #imageLiteral(resourceName: "ProfilePic").withRenderingMode(.alwaysOriginal)
           return view
       }
   } else {
       // Fallback on earlier versions
       return nil
   }
}
return view

Note:

  • Set the profileImage to a 24x24 icon.
  • An optional String representing the initials of the person being annotated. Font style is fixed and does not change with accessibility. glyphText is only displayed when there is no glyphImage available and is limited to 2 characters.

    Declaration

    Swift

    override open var glyphText: String? { get set }
  • Profile image to display when the annotationView is first loaded.

    Declaration

    Swift

    override open var glyphImage: UIImage? { get set }
  • Optional profile image to display when the annotationView is in a selected state. Will use glyphImage if not supplied.

    Declaration

    Swift

    override open var selectedGlyphImage: UIImage? { get set }
  • An initializer that instantiates a FUIProfileMarkerAnnotationView with some reuseIdentifier. Sets the tint color to a default value of .map1

    Declaration

    Swift

    override public init(annotation: MKAnnotation?, reuseIdentifier: String?)