Snapshotter

public class Snapshotter
extension Snapshotter: MapEventsObservable

A high-level component responsible for taking map snapshots with given MapSnapshotOptions.

  • A style object that can be manipulated to set different styles for a snapshot

    Declaration

    Swift

    public let style: Style
  • Initialize a Snapshotter instance

    Declaration

    Swift

    public init(options: MapSnapshotOptions)

    Parameters

    options

    Options describing an intended snapshot

  • The size of the snapshot

    Declaration

    Swift

    public var snapshotSize: CGSize { get set }
  • The current camera state of the snapshotter

    Declaration

    Swift

    public var cameraState: CameraState { get }
  • Sets the camera of the snapshotter

    Declaration

    Swift

    public func setCamera(to cameraOptions: CameraOptions)

    Parameters

    cameraOptions

    The target camera options

  • In the tile mode, the snapshotter fetches the still image of a single tile.

    Declaration

    Swift

    @available(*, deprecated, message: "This property will be removed in a future major version")
    public var tileMode: Bool { get set }
  • Request a new snapshot. If there is a pending snapshot request, it is cancelled automatically.

    Declaration

    Swift

    public func start(overlayHandler: SnapshotOverlayHandler?,
                      completion: @escaping (Result<UIImage, SnapshotError>) -> Void)

    Parameters

    overlayHandler

    The optional block to call after the base map finishes drawing, but before the final snapshot has been drawn. This block provides a SnapshotOverlayHandler type, which can be used with Core Graphics to draw custom content directly over the snapshot image.

    completion

    The block to call once the snapshot has been generated, providing a Result<UIImage, SnapshotError> type.

  • Cancels the current snapshot operation.The callback passed to the start method is called with error parameter set.

    Declaration

    Swift

    public func cancel()
  • Undocumented

    See more

    Declaration

    Swift

    public enum SnapshotError : Error
  • Returns the coordinate bounds corresponding to a given CameraOptions

    Declaration

    Swift

    public func coordinateBounds(for camera: CameraOptions) -> CoordinateBounds

    Parameters

    camera

    The camera for which the coordinate bounds will be returned.

    Return Value

    CoordinateBounds for the given CameraOptions

  • Calculates a CameraOptions to fit a list of coordinates.

    Declaration

    Swift

    public func camera(for coordinates: [CLLocationCoordinate2D],
                       padding: UIEdgeInsets,
                       bearing: Double?,
                       pitch: Double?) -> CameraOptions

    Parameters

    coordinates

    Array of coordinates that should fit within the new viewport.

    padding

    The new padding to be used by the camera.

    bearing

    The new bearing to be used by the camera.

    pitch

    The new pitch to be used by the camera.

    Return Value

    A CameraOptions that fits the provided constraints

  • Subscribes an observer to a list of events.

    Snapshotter holds a strong reference to observer while it is subscribed. To stop receiving notifications, pass the same observer to unsubscribe(_:events:).

    Note

    Prefer onNext(_:handler:) and onEvery(_:handler:) to using this lower-level APIs

    Declaration

    Swift

    public func subscribe(_ observer: Observer, events: [String])

    Parameters

    observer

    An object that will receive events of the types specified by events

    events

    Array of event types to deliver to observer

  • Unsubscribes an observer from a list of events.

    Snapshotter holds a strong reference to observer while it is subscribed. To stop receiving notifications, pass the same observer to this method as was passed to subscribe(_:events:).

    Declaration

    Swift

    public func unsubscribe(_ observer: Observer, events: [String] = [])

    Parameters

    observer

    The object to unsubscribe

    events

    Array of event types to unsubscribe from. Pass an empty array (the default) to unsubscribe from all events.

  • Listen to a single occurrence of a Map event.

    This will observe the next (and only the next) event of the specified type. After observation, the underlying subscriber will unsubscribe from the map or snapshotter.

    If you need to unsubscribe before the event fires, call cancel() on the returned Cancelable object.

    Declaration

    Swift

    @available(*, deprecated, renamed: "onNext(event:handler:﹚")
    @discardableResult
    public func onNext(_ eventType: MapEvents.EventKind, handler: @escaping (Event) -> Void) -> Cancelable

    Parameters

    eventType

    The event type to listen to.

    handler

    The closure to execute when the event occurs.

    Return Value

    A Cancelable object that you can use to stop listening for the event. This is especially important if you have a retain cycle in the handler.

  • Listen to a single occurrence of a Map event.

    This will observe the next (and only the next) event of the specified type. After observation, the underlying subscriber will unsubscribe from the map or snapshotter.

    If you need to unsubscribe before the event fires, call cancel() on the returned Cancelable object.

    Declaration

    Swift

    @discardableResult
    public func onNext<Payload>(event: MapEvents.Event<Payload>, handler: @escaping (MapEvent<Payload>) -> Void) -> Cancelable where Payload : Decodable

    Parameters

    eventType

    The event type to listen to.

    handler

    The closure to execute when the event occurs.

    Return Value

    A Cancelable object that you can use to stop listening for the event. This is especially important if you have a retain cycle in the handler.

  • Listen to multiple occurrences of a Map event.

    Declaration

    Swift

    @available(*, deprecated, renamed: "onEvery(event:handler:﹚")
    @discardableResult
    public func onEvery(_ eventType: MapEvents.EventKind, handler: @escaping (Event) -> Void) -> Cancelable

    Parameters

    eventType

    The event type to listen to.

    handler

    The closure to execute when the event occurs.

    Return Value

    A Cancelable object that you can use to stop listening for events. This is especially important if you have a retain cycle in the handler.

  • Listen to multiple occurrences of a Map event.

    Declaration

    Swift

    @discardableResult
    public func onEvery<Payload>(event: MapEvents.Event<Payload>, handler: @escaping (MapEvent<Payload>) -> Void) -> Cancelable where Payload : Decodable

    Parameters

    eventType

    The event type to listen to.

    handler

    The closure to execute when the event occurs.

    Return Value

    A Cancelable object that you can use to stop listening for events. This is especially important if you have a retain cycle in the handler.

  • Clears temporary map data.

    Clears temporary map data from the data path defined in the given resource options. Useful to reduce the disk usage or in case the disk cache contains invalid data.

    Note

    Calling this API will affect all maps that use the same data path and does not affect persistent map data like offline style packages.

    Declaration

    Swift

    public func clearData(completion: @escaping (Error?) -> Void)

    Parameters

    completion

    Called once the request is complete