diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-10-09 19:50:21 +0300 |
---|---|---|
committer | Fabian Guerra Soto <fabian.guerra@mapbox.com> | 2017-11-01 09:23:53 -0400 |
commit | de9098cf99463e433e9e9d6088865bc63948e567 (patch) | |
tree | 45669b918e2549e367742cb2e924f69277febf7a /platform/darwin/src/MGLMapSnapshotter.mm | |
parent | 9c3e78a9b95782e8fbf15cf7a4052f46f27922fd (diff) | |
download | qtlocation-mapboxgl-de9098cf99463e433e9e9d6088865bc63948e567.tar.gz |
[darwin][ios][macos] map snapshotter - add MGLMapSnapshot wrapper
Diffstat (limited to 'platform/darwin/src/MGLMapSnapshotter.mm')
-rw-r--r-- | platform/darwin/src/MGLMapSnapshotter.mm | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/platform/darwin/src/MGLMapSnapshotter.mm b/platform/darwin/src/MGLMapSnapshotter.mm index 9d32ecf72c..193548ac11 100644 --- a/platform/darwin/src/MGLMapSnapshotter.mm +++ b/platform/darwin/src/MGLMapSnapshotter.mm @@ -49,6 +49,33 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64; @end +@interface MGLMapSnapshot() +- (instancetype)initWithImage:(nullable MGLImage *)image scale:(CGFloat)scale pointForFn:(mbgl::MapSnapshotter::PointForFn)pointForFn; + +@property (nonatomic) CGFloat scale; +@end + +@implementation MGLMapSnapshot { + mbgl::MapSnapshotter::PointForFn _pointForFn; +} +- (instancetype)initWithImage:(nullable MGLImage *)image scale:(CGFloat)scale pointForFn:(mbgl::MapSnapshotter::PointForFn)pointForFn +{ + self = [super init]; + if (self) { + _pointForFn = std::move(pointForFn); + _scale = scale; + _image = image; + } + return self; +} + +- (CGPoint)pointForCoordinate:(CLLocationCoordinate2D)coordinate +{ + mbgl::ScreenCoordinate sc = _pointForFn(MGLLatLngFromLocationCoordinate2D(coordinate)); + return CGPointMake(sc.x * self.scale, sc.y * self.scale); +} +@end + @interface MGLMapSnapshotter() @property (nonatomic) MGLMapSnapshotOptions *options; @end @@ -117,7 +144,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64; _loading = true; dispatch_async(queue, ^{ - _snapshotCallback = std::make_unique<mbgl::Actor<mbgl::MapSnapshotter::Callback>>(*mbgl::Scheduler::GetCurrent(), [=](std::exception_ptr mbglError, mbgl::PremultipliedImage image) { + _snapshotCallback = std::make_unique<mbgl::Actor<mbgl::MapSnapshotter::Callback>>(*mbgl::Scheduler::GetCurrent(), [=](std::exception_ptr mbglError, mbgl::PremultipliedImage image, mbgl::MapSnapshotter::PointForFn pointForFn) { _loading = false; if (mbglError) { NSString *description = @(mbgl::util::toString(mbglError).c_str()); @@ -171,7 +198,8 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64; // Dispatch result to origin queue dispatch_async(queue, ^{ - completion(compositedImage, nil); + MGLMapSnapshot* snapshot = [[MGLMapSnapshot alloc] initWithImage:compositedImage scale:self.options.scale pointForFn:pointForFn]; + completion(snapshot, nil); }); }); } @@ -189,7 +217,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64; - (NSURL *)styleURL { NSString *styleURLString = @(_mbglMapSnapshotter->getStyleURL().c_str()); - return styleURLString && styleURLString.length > 0 ? [NSURL URLWithString:styleURLString] : nil; + return styleURLString.length ? [NSURL URLWithString:styleURLString] : nil; } - (void)setStyleURL:(NSURL *)url |