Other Classes

The following classes are available globally.

  • Creates a view annotation.

    Use view annotations if you need to display interactive UIView bound to a geographical coordinate or map feature.

    If you need to display large amounts of data or clustering, please consider using PointAnnotation or Runtime Styling API, for example, SymbolLayer with GeoJSONSource.

    To display a view annotation configure a UIView, create ViewAnnotation, and add it to the view annotation manager:

    let view = CustomView()
    view.icon = UIImage(named: "traffic-icon")
    let annotation = ViewAnnotation(
      coordinate: CLLocationCoordinate(latitude: 10, longitude: 10),
      view: view)
    mapView.viewAnnotations.add(annotation)
    

    The annotation can be displayed on a layer feature referenced by it’s layerId and featureId:

    annotation.annotatedFeature = .layerFeature(layerId: "route-line", featureId: "sf-la")
    

    The view annotation automatically inserts and removes it’s view into the view hierarchy and updates its isHidden property.

    Important

    Don’t set UIView.isHidden property to hide the annotation. Instead, use visible property.

    When view content or layout is updated, use setNeedsUpdateSize() to update the the annotation size. It’s safe to use it multiple times, only one update will be performed.

    view.hintText = "Less Traffic"
    annotation.setNeedsUpdateSize() // Updates the annotation size.
    

    Note

    The ViewAnnotation uses UIView.systemLayoutSizeFitting(_:) to measure the view size. Make sure that your view returns the correct size (e.g. implemented using AutoLayout, or returns correct size from UIView.sizeThatFits(_:) when layout is manual).

    To remove annotation when it’s no longer needed, use remove() method.

    See more

    Declaration

    Swift

    public final class ViewAnnotation
  • A Cancellable object that automatically cancels on deinit.

    Any resources referred by AnyCancelable will be released after cancellation.

    This class has similar behavior to Combine.AnyCancellable, but doesn’t require iOS 13.

    See more

    Declaration

    Swift

    public class AnyCancelable : Cancelable
    extension AnyCancelable: Hashable
  • MapboxRecorder provides functions to record and replay API calls of a MapboxMap instance. These recordings can be used to debug issues which require multiple steps to reproduce. Additionally, playbacks can be used for performance testing custom scenarios.

    Note

    The file format produced by MapRecorder is experimental and there is no guarantee for version cross-compatibility. The set of recorded APIs and their parameters might change in future releases.
    See more

    Declaration

    Swift

    @_spi(Experimental)
    public final class MapRecorder
  • Style provides access to the APIs used to dynamically modify the map’s style. Use it to read and write layers, sources, and images. Obtain the Style instance for a MapView via MapView.mapboxMap.style.

    Important

    Style should only be used from the main thread.
    See more

    Declaration

    Swift

    public class StyleManager
  • Viewport provides a structured approach to organizing camera management logic into states and transitions between them.

    At any given time, the viewport is either:

    See more

    Declaration

    Swift

    public final class ViewportManager