MGLMapSnapshotter
@interface MGLMapSnapshotter : NSObjectAn MGLMapSnapshotter generates static raster images of the map. Each snapshot
image depicts a portion of a map defined by an MGLMapSnapshotOptions object
you provide. The snapshotter generates an MGLMapSnapshot object
asynchronously, passing it into a completion handler once tiles and other
resources needed for the snapshot are finished loading.
You can change the snapshotter’s options at any time and reuse the snapshotter for multiple distinct snapshots; however, the snapshotter can only generate one snapshot at a time. If you need to generate multiple snapshots concurrently, create multiple snapshotter objects.
For an interactive map, use the MGLMapView class. Both MGLMapSnapshotter
and MGLMapView are compatible with offline packs managed by the
MGLOfflineStorage class.
From a snapshot, you can obtain an image and convert geographic coordinates to
the image’s coordinate space in order to superimpose markers and overlays. If
you do not need offline map functionality, you can use the Snapshot class in
MapboxStatic.swift to generate
static map images with overlays.
Example
let camera = MGLMapCamera(lookingAtCenter: CLLocationCoordinate2D(latitude: 37.7184, longitude: -122.4365), altitude: 100, pitch: 20, heading: 0)
let options = MGLMapSnapshotOptions(styleURL: MGLStyle.satelliteStreetsStyleURL, camera: camera, size: CGSize(width: 320, height: 480))
options.zoomLevel = 10
let snapshotter = MGLMapSnapshotter(options: options)
snapshotter.start { (snapshot, error) in
    if let error = error {
        fatalError(error.localizedDescription)
    }
    image = snapshot?.image
}
Related examples
See the 
Create a static map snapshot example to learn how to use the
MGLMapSnapshotter to generate a static image based on an MGLMapView
object’s style, camera, and view bounds.
- 
                  
                  Initializes and returns a map snapshotter object that produces snapshots according to the given options. DeclarationObjective-C - (nonnull instancetype)initWithOptions: (nonnull MGLMapSnapshotOptions *)options;Swift init(options: MGLMapSnapshotOptions)ParametersoptionsThe options to use when generating a map snapshot. Return ValueAn initialized map snapshotter. 
- 
                  
                  Starts the snapshot creation and executes the specified block with the result. DeclarationObjective-C - (void)startWithCompletionHandler: (nonnull MGLMapSnapshotCompletionHandler)completionHandler;Swift func start(completionHandler: @escaping MGLMapSnapshotCompletionHandler)ParameterscompletionHandlerThe block to handle the result in. 
- 
                  
                  Starts the snapshot creation and executes the specified block with the result on the specified queue. DeclarationObjective-C - (void)startWithQueue:(nonnull dispatch_queue_t)queue completionHandler: (nonnull MGLMapSnapshotCompletionHandler)completionHandler;Swift func start(with queue: DispatchQueue, completionHandler: @escaping MGLMapSnapshotCompletionHandler)ParametersqueueThe queue to handle the result on. completionHandlerThe block to handle the result in. 
- 
                  
                  Cancels the snapshot creation request, if any. Once you call this method, you cannot resume the snapshot. In order to obtain the snapshot, create a new MGLMapSnapshotterobject.DeclarationObjective-C - (void)cancel;Swift func cancel()
- 
                  
                  The options to use when generating a map snapshot. DeclarationObjective-C @property (assign, readwrite, nonatomic) MGLMapSnapshotOptions *_Nonnull options;Swift var options: MGLMapSnapshotOptions { get set }
- 
                  
                  Indicates whether a snapshot is currently being generated. DeclarationObjective-C @property (readonly, getter=isLoading, nonatomic) BOOL loading;Swift var isLoading: Bool { get }
 Install in Dash
              Install in Dash
             MGLMapSnapshotter Class Reference
        MGLMapSnapshotter Class Reference