Add private property to determine whether the snapshotter logo is displayed. (#159)

This commit is contained in:
Julian Rex
2020-02-11 15:11:36 -05:00
committed by GitHub
parent 5df56ada54
commit ca85ea2b28
2 changed files with 34 additions and 8 deletions

View File

@@ -91,6 +91,21 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
#endif
@end
@interface MGLMapSnapshotOptions ()
/**
:nodoc:
Whether the Mapbox wordmark is displayed.
@note The Mapbox terms of service, which governs the use of Mapbox-hosted
vector tiles and styles,
<a href="https://docs.mapbox.com/help/how-mapbox-works/attribution/">requires</a> most Mapbox
customers to display the Mapbox wordmark. If this applies to you, do not
hide the wordmark or change its contents.
*/
@property (nonatomic, readwrite) BOOL showsLogo;
@end
@implementation MGLMapSnapshotOptions
- (instancetype _Nonnull)initWithStyleURL:(nullable NSURL *)styleURL camera:(MGLMapCamera *)camera size:(CGSize)size
@@ -106,6 +121,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
_styleURL = styleURL;
_size = size;
_camera = camera;
_showsLogo = YES;
#if TARGET_OS_IPHONE
_scale = [UIScreen mainScreen].scale;
#else
@@ -321,7 +337,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
_mbglMapSnapshotter->snapshot(_snapshotCallback->self());
}
+ (MGLImage*)drawAttributedSnapshotWorker:(mbgl::MapSnapshotter::Attributions)attributions snapshotImage:(MGLImage *)mglImage pointForFn:(mbgl::MapSnapshotter::PointForFn)pointForFn latLngForFn:(mbgl::MapSnapshotter::LatLngForFn)latLngForFn scale:(CGFloat)scale size:(CGSize)size overlayHandler:(MGLMapSnapshotOverlayHandler)overlayHandler {
+ (MGLImage*)drawAttributedSnapshotWorker:(mbgl::MapSnapshotter::Attributions)attributions snapshotImage:(MGLImage *)mglImage pointForFn:(mbgl::MapSnapshotter::PointForFn)pointForFn latLngForFn:(mbgl::MapSnapshotter::LatLngForFn)latLngForFn scale:(CGFloat)scale size:(CGSize)size showsLogo:(BOOL)showsLogo overlayHandler:(MGLMapSnapshotOverlayHandler)overlayHandler {
NSArray<MGLAttributionInfo *>* attributionInfo = [MGLMapSnapshotter generateAttributionInfos:attributions];
@@ -334,7 +350,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
break;
}
}
UIImage *logoImage = [MGLMapSnapshotter logoImageWithStyle:attributionInfoStyle];
CGSize attributionBackgroundSize = [MGLMapSnapshotter attributionTextSizeWithStyle:attributionInfoStyle attributionInfo:attributionInfo];
@@ -383,7 +399,9 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
return nil;
}
[logoImage drawInRect:logoImageRect];
if (showsLogo) {
[logoImage drawInRect:logoImageRect];
}
UIImage *currentImage = UIGraphicsGetImageFromCurrentImageContext();
CGImageRef attributionImageRef = CGImageCreateWithImageInRect([currentImage CGImage], cropRect);
@@ -494,15 +512,23 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
dispatch_queue_t resultQueue = self.resultQueue;
// Capture scale and size by value to avoid accessing self from another thread
CGFloat scale = self.options.scale;
CGSize size = self.options.size;
CGFloat scale = self.options.scale;
CGSize size = self.options.size;
BOOL showsLogo = self.options.showsLogo;
// pointForFn is a copyable std::function that captures state by value: see MapSnapshotter::Impl::snapshot
__weak __typeof__(self) weakself = self;
dispatch_async(workQueue, ^{
// Call a class method to ensure we're not accidentally capturing self
MGLImage *compositedImage = [MGLMapSnapshotter drawAttributedSnapshotWorker:attributions snapshotImage:mglImage pointForFn:pointForFn latLngForFn:latLngForFn scale:scale size:size overlayHandler:overlayHandler];
MGLImage *compositedImage = [MGLMapSnapshotter drawAttributedSnapshotWorker:attributions
snapshotImage:mglImage
pointForFn:pointForFn
latLngForFn:latLngForFn
scale:scale
size:size
showsLogo:showsLogo
overlayHandler:overlayHandler];
// Dispatch result to origin queue
dispatch_async(resultQueue, ^{

View File

@@ -355,12 +355,12 @@ MGL_EXPORT
@property (nonatomic, assign) CGPoint compassViewMargins;
/**
The Mapbox logo, positioned in the lower-left corner.
The Mapbox wordmark, positioned in the lower-left corner.
@note The Mapbox terms of service, which governs the use of Mapbox-hosted
vector tiles and styles,
<a href="https://docs.mapbox.com/help/how-mapbox-works/attribution/">requires</a> most Mapbox
customers to display the Mapbox logo. If this applies to you, do not
customers to display the Mapbox wordmark. If this applies to you, do not
hide this view or change its contents.
*/
@property (nonatomic, readonly) UIImageView *logoView;