AnnotationManager

public class AnnotationManager

Manages the addition, update, and the deletion of annotations to a map.

All annotations added with this class belong to a single source and style layer.

  • A dictionary of key/value pairs being managed by the AnnotationManager, where the key represents the unique identifier of the annotation and the value refers to the Annotation itself.

    Note

    This property is get-only, so it cannot be used to add or remove annotations. Instead, use the addAnnotation or removeAnnotation related methods update annotations belonging to the map view.

    Declaration

    Swift

    public private(set) var annotations: [String : Annotation] { get }
  • The delegate to notify of changes in annotations.

    Declaration

    Swift

    public weak var interactionDelegate: AnnotationInteractionDelegate?
  • An array of annotations that have currently been selected by the annotation manager.

    Declaration

    Swift

    public var selectedAnnotations: [Annotation] { get }
  • A Bool value that indicates whether users can interact with the annotations managed by the annotation manager. The default value is true. Setting this property to false will deinitialize the annotation manager’s tap gesture recognizer.

    Declaration

    Swift

    public var userInteractionEnabled: Bool { get set }
  • Adds a given annotation to the MapView.

    If the given annotation has already been added to the MapView, this returns an error.

    Declaration

    Swift

    @discardableResult
    public func addAnnotation(_ annotation: Annotation) -> Result<Bool, AnnotationError>

    Parameters

    annotation

    Annotation to add to the MapView.

    Return Value

    If operation successful, returns a true as part of the Result success case. Else, returns a AnnotationError in the Result failure case.

  • Adds a given array of annotations to the MapView.

    The method is equivalent to calling addAnnotation(_ annotation:) method for each annotation within the group.

    Declaration

    Swift

    @discardableResult
    public func addAnnotations(_ annotations: [Annotation]) -> Result<Bool, AnnotationError>

    Parameters

    annotations

    Annotations to add to the MapView.

  • Updates the annotation registered with the annotation manager.

    Throws

    AnnotationError.annotationDoesNotExist if the annotation hasn’t been added, otherwise throws AnnotationError.updateAnnotationFailed.

    Declaration

    Swift

    public func updateAnnotation(_ annotation: Annotation) throws

    Parameters

    annotation

    The annotation that should be updated.

  • Removes a given annotation from the MapView.

    If the given annotation has already been removed from the MapView, this returns an error.

    Declaration

    Swift

    @discardableResult
    public func removeAnnotation(_ annotation: Annotation) -> Result<Bool, AnnotationError>

    Parameters

    annotation

    Annotation to remove from the MapView.

    Return Value

    If operation successful, returns a true as part of the Result success case. Else, returns a AnnotationError in the Result failure case.

  • Removes a given array of annotations from the MapView.

    The method is equivalent to calling removeAnnotation(_ annotation:) method for each annotation within the group.

    Declaration

    Swift

    @discardableResult
    public func removeAnnotations(_ annotations: [Annotation]) -> Result<Bool, AnnotationError>

    Parameters

    annotations

    Annotations to remove from the MapView.

  • Toggles the annotation’s selection state. If the annotation is deselected, it becomes selected. If the annotation is selected, it becomes deselected.

    Declaration

    Swift

    public func selectAnnotation(_ annotation: Annotation)

    Parameters

    Annotations

    The annotation to select.

  • Returns the underlying layer identifier for the associated annotation type.

    Declaration

    Swift

    public func layerId<T>(for annotationType: T.Type) -> String? where T : Annotation

    Parameters

    annotationType

    Type of annotation, for example, PointAnnotation.self

    Return Value

    Identifier (or nil, if there isn’t a layer for that type)