Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Streamline MGLMapSnapshotter; upgrade to Mapbox GL Native v1.4.0 #210

Merged
merged 6 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions platform/darwin/scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ global.propertyDoc = function (propertyName, property, layerType, kind) {
let doc = property.doc.replace(/`([^`]+?)` is set to `([^`]+?)`(?: or `([^`]+?)`)?/g, function (m, peerPropertyName, propertyValue, secondPropertyValue, offset, str) {
let otherProperty = camelizeWithLeadingLowercase(peerPropertyName);
let otherValue = objCType(layerType, peerPropertyName) + camelize(propertyValue);
if (propertyValue === 'true' || propertyValue === 'false') {
otherValue = propertyValue === 'true' ? 'YES' : 'NO';
}
if (property.type == 'array' && kind == 'light') {
otherValue = propertyValue;
}
Expand Down
47 changes: 38 additions & 9 deletions platform/darwin/src/MGLMapSnapshotter.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ typedef void (^MGLMapSnapshotOverlayHandler)(MGLMapSnapshotOverlay * snapshotOve
The options to use when creating images with the `MGLMapSnapshotter`.
*/
MGL_EXPORT
@interface MGLMapSnapshotOptions : NSObject
@interface MGLMapSnapshotOptions : NSObject <NSCopying>

/**
Creates a set of options with the minimum required information.
Expand Down Expand Up @@ -185,6 +185,11 @@ typedef void (^MGLMapSnapshotCompletionHandler)(MGLMapSnapshot* _Nullable snapsh
snapshot at a time. If you need to generate multiple snapshots concurrently,
create multiple snapshotter objects.

An `MGLMapSnapshotter` object may be deallocated before the completion handler
is called. To prevent this object from being deallocated prematurely, maintain
a strong reference to it, for example by storing it in an instance variable of
the class where you initialize and start the snapshotter.

For an interactive map, use the `MGLMapView` class. Both `MGLMapSnapshotter`
and `MGLMapView` are compatible with offline packs managed by the
`MGLOfflineStorage` class.
Expand All @@ -203,7 +208,8 @@ typedef void (^MGLMapSnapshotCompletionHandler)(MGLMapSnapshot* _Nullable snapsh
let options = MGLMapSnapshotOptions(styleURL: MGLStyle.satelliteStreetsStyleURL, camera: camera, size: CGSize(width: 320, height: 480))
options.zoomLevel = 10

let snapshotter = MGLMapSnapshotter(options: options)
// The containing class should hold a strong reference to this object.
snapshotter = MGLMapSnapshotter(options: options)
snapshotter.start { (snapshot, error) in
if let error = error {
fatalError(error.localizedDescription)
Expand Down Expand Up @@ -236,25 +242,48 @@ MGL_EXPORT
/**
Starts the snapshot creation and executes the specified block with the result.

@param completionHandler The block to handle the result in.
The snapshotter may be deallocated before the completion handler is called. To
prevent the snapshotter from being deallocated prematurely, maintain a strong
reference to it, for example by storing it in an instance variable of the class
where you call this method.

@param completionHandler The block to call with a finished snapshot. The block
is executed on the main queue.
*/
- (void)startWithCompletionHandler:(MGLMapSnapshotCompletionHandler)completionHandler;

/**
Starts the snapshot creation and executes the specified block with the result
on the specified queue.

@param queue The queue to handle the result on.
@param completionHandler The block to handle the result in.
The snapshotter may be deallocated before the completion handler is called. To
prevent the snapshotter from being deallocated prematurely, maintain a strong
reference to it, for example by storing it in an instance variable of the class
where you call this method.

@param queue The queue on which to call the block specified in the
`completionHandler` parameter.
@param completionHandler The block to call with a finished snapshot. The block
is executed on the queue specified in the `queue` parameter.
*/
- (void)startWithQueue:(dispatch_queue_t)queue completionHandler:(MGLMapSnapshotCompletionHandler)completionHandler;

/**
Starts the snapshot creation and executes the specified blocks with the result
on the specified queue. Use this option if you want to add custom drawing on top of the
resulting `MGLMapSnapShot`.
@param overlayHandler The block to handle manipulation of the `MGLMapSnapshotter`'s `CGContext`.
@param completionHandler The block to handle the result in.
on the specified queue. Use this option if you want to add custom drawing on
top of the resulting `MGLMapSnapshot`.

The snapshotter may be deallocated before the completion handler is called. To
prevent the snapshotter from being deallocated prematurely, maintain a strong
reference to it, for example by storing it in an instance variable of the class
where you call this method.

@param overlayHandler The block to call after the base map finishes drawing but
before certain built-in overlays draw. The block can use Core Graphics to
draw custom content directly over the base map. The block is executed on a
background queue.
@param completionHandler The block to call with a finished snapshot. The block
is executed on the main queue.
*/
- (void)startWithOverlayHandler:(MGLMapSnapshotOverlayHandler)overlayHandler completionHandler:(MGLMapSnapshotCompletionHandler)completionHandler;

Expand Down
Loading