MapViewAnnotation

@available(iOS 13.0, *)
@_documentation(visibility: public)
@_spi(Experimental)
public struct MapViewAnnotation : MapContent

Displays a view annotation.

Create a view annotation to display an interactive SwiftUI view bound to geographical coordinate or map feature. MapViewAnnotation is a SwiftUI analog to ViewAnnotation.

Map {
    MapViewAnnotation(coordinate: CLLocationCoordinate2D(...)) {
       Text("🚀")
          .background(Circle().fill(.red))
    }
}
  • Creates a view annotation at geographical coordinate.

    Declaration

    Swift

    @available(iOS 13.0, *)
    @_documentation(visibility: public)
    public init<Content: View>(
        coordinate: CLLocationCoordinate2D,
        @ViewBuilder content: @escaping () -> Content
    )

    Parameters

    coordinate

    Coordinate the view annotation is bound to.

    content

    The view to place on the map.

  • Creates a view annotation on feature rendered on a layer.

    Declaration

    Swift

    @available(iOS 13.0, *)
    @_documentation(visibility: public)
    public init<Content: View>(
        layerId: String,
        featureId: String? = nil,
        @ViewBuilder content: @escaping () -> Content
    )

    Parameters

    layerId

    Layer identifier which renders the feature.

    featureId

    Feature identifier. If not specified, the annotation will appear on any feature from that layer.

    content

    The view to place on the map.

  • Creates a view annotation.

    Declaration

    Swift

    @available(iOS 13.0, *)
    @_documentation(visibility: public)
    public init<Content: View>(
        annotatedFeature: AnnotatedFeature,
        @ViewBuilder content: @escaping () -> Content
    )

    Parameters

    annotatedFeature

    Associates the view annotation with the feature geometry. The geometry may be any Geometry, or a feature rendered on a specified layer.

    content

    The view to place on the map.

  • If true, the annotation will be visible even if it collides with other annotations. Defaults to false.

    Declaration

    Swift

    @_documentation(visibility: public)
    public func allowOverlap(_ allowOverlap: Bool) -> MapViewAnnotation
  • Specifies if this view annotation is visible or not. Defaults to true.

    Declaration

    Swift

    @_documentation(visibility: public)
    public func visible(_ visible: Bool) -> MapViewAnnotation
  • Specifies if this view annotation is selected meaning it should be placed on top of others. Defaults to false.

    Declaration

    Swift

    @_documentation(visibility: public)
    public func selected(_ selected: Bool = false) -> MapViewAnnotation
  • A list of anchor configurations available.

    The annotation will automatically pick the first best anchor position depending on position relative to other elements on the map.

    The onAnchorChanged is called when the effective position is updated.

    If not specified, the annotation will be placed in center.

    Declaration

    Swift

    @_documentation(visibility: public)
    public func variableAnchors(_ variableAnchors: [ViewAnnotationAnchorConfig]) -> MapViewAnnotation
  • Called when anchor configuration is changed.

    See variableAnchors(_:).

    The callback takes the anchorConfig parameter which represents the selected anchor configuration.

    Declaration

    Swift

    @_documentation(visibility: public)
    public func onAnchorChanged(action: @escaping (ViewAnnotationAnchorConfig) -> Void) -> MapViewAnnotation
  • Called when visibility of annotation is changed.

    The annotation becomes hidden when it goes out of MapView’s bounds or visible(_:) is changed.

    The callback takes true when annotation is visible.

    Declaration

    Swift

    @_documentation(visibility: public)
    public func onVisibilityChanged(action: @escaping (Bool) -> Void) -> MapViewAnnotation
  • Called when geographical coordinate of annotation anchor is changed.

    Declaration

    Swift

    @_documentation(visibility: public)
    public func onAnchorCoordinateChanged(action: @escaping (CLLocationCoordinate2D) -> Void) -> MapViewAnnotation