MGLAnnotationView

@interface MGLAnnotationView : UIView

The MGLAnnotationView class is responsible for representing point-based annotation markers as a view. Annotation views represent an annotation object, which is an object that corresponds to the MGLAnnotation protocol. When an annotation’s coordinate point is visible on the map view, the map view delegate is asked to provide a corresponding annotation view. If an annotation view is created with a reuse identifier, the map view may recycle the view when it goes offscreen.

  • Initializes and returns a new annotation view object.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithReuseIdentifier:
        (nullable NSString *)reuseIdentifier;

    Swift

    init!(reuseIdentifier: AnyObject!)

    Parameters

    reuseIdentifier

    The string that identifies that this annotation view is reusable.

    Return Value

    The initialized annotation view object.

  • The string that identifies that this annotation view is reusable. (read-only)

    You specify the reuse identifier when you create the view. You use the identifier later to retrieve an annotation view that was created previously but which is currently unused because its annotation is not on screen.

    If you define distinctly different types of annotations (with distinctly different annotation views to go with them), you can differentiate between the annotation types by specifying different reuse identifiers for each one.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) NSString *reuseIdentifier;

    Swift

    var reuseIdentifier: UnsafeMutablePointer
  • Annotation view is centered at the coordinate point of the associated annotation.

    By changing this property you can reposition the view as needed. The offset is measured in points. Positive offset moves the annotation view towards the bottom right, while negative offset moves it towards the top left.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) CGVector centerOffset;

    Swift

    var centerOffset: Int32 { get set }
  • Setting this property to YES will force the annotation view to tilt according to the associated map view.

    Declaration

    Objective-C

    @property (getter=isFlat, assign, readwrite, nonatomic) BOOL flat;

    Swift

    var flat: Int32 { get set }
  • Setting this property to YES will cause the annotation view to shrink as it approaches the horizon and grow as it moves away from the horizon when the associated map view is tilted. Conversely, setting this property to NO will ensure that the annotation view maintains a constant size even when the map view is tilted. To maintain consistency with annotation representations that are not backed by an MGLAnnotationView object, the default value of this property is YES.

    Declaration

    Objective-C

    @property (getter=isScaledWithViewingDistance, assign, readwrite, nonatomic)
        BOOL scalesWithViewingDistance;

    Swift

    var scalesWithViewingDistance: Int32 { get set }
  • Called when the view is removed from the reuse queue.

    The default implementation of this method does nothing. You can override it in your custom annotation views and use it to put the view in a known state before it is returned to your map view delegate.

    Declaration

    Objective-C

    - (void)prepareForReuse;

    Swift

    func prepareForReuse()