From f6184d81d42fe8e263428a4a08446edd00ffea56 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Thu, 14 Dec 2017 16:44:00 -0600 Subject: [ios, macos] Remove duplicated variables between MGLMapSnapshotOptions and MGLMapSnapshotter --- platform/darwin/src/MGLMapSnapshotter.h | 39 +-------- platform/darwin/src/MGLMapSnapshotter.mm | 138 ++++++++----------------------- 2 files changed, 35 insertions(+), 142 deletions(-) diff --git a/platform/darwin/src/MGLMapSnapshotter.h b/platform/darwin/src/MGLMapSnapshotter.h index 978e19dc20..fc68204a7d 100644 --- a/platform/darwin/src/MGLMapSnapshotter.h +++ b/platform/darwin/src/MGLMapSnapshotter.h @@ -190,44 +190,9 @@ MGL_EXPORT - (void)cancel; /** - The zoom level. - - The default zoom level is 0. If this property is non-zero and the camera - property is non-nil, the camera’s altitude is ignored in favor of this - property’s value. - */ -@property (nonatomic) double zoomLevel; - -/** - A camera representing the viewport visible in the snapshot. - - If this property is non-nil and the `coordinateBounds` property is set to a - non-empty coordinate bounds, the camera’s center coordinate and altitude are - ignored in favor of the `coordinateBounds` property. - */ -@property (nonatomic) MGLMapCamera *camera; - -/** - The coordinate rectangle that encompasses the bounds to capture. - - If this property is non-empty and the camera property is non-nil, the camera’s - center coordinate and altitude are ignored in favor of this property’s value. - */ -@property (nonatomic) MGLCoordinateBounds coordinateBounds; - -/** - URL of the map style to snapshot. - - The URL may be a full HTTP or HTTPS URL, a Mapbox URL indicating the style’s - map ID (`mapbox://styles/{user}/{style}`), or a path to a local file relative - to the application’s resource path. Specify `nil` for the default style. - */ -@property (nonatomic, nullable) NSURL *styleURL; - -/** - The size of the output image, measured in points. + The options to use when generating a map snapshot. */ -@property (nonatomic) CGSize size; +@property (nonatomic) MGLMapSnapshotOptions *options; /** Indicates whether a snapshot is currently being generated. diff --git a/platform/darwin/src/MGLMapSnapshotter.mm b/platform/darwin/src/MGLMapSnapshotter.mm index 8b54488814..15a8f6c8ca 100644 --- a/platform/darwin/src/MGLMapSnapshotter.mm +++ b/platform/darwin/src/MGLMapSnapshotter.mm @@ -81,7 +81,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64; @end @interface MGLMapSnapshotter() -@property (nonatomic) MGLMapSnapshotOptions *options; + @end @implementation MGLMapSnapshotter { @@ -96,40 +96,9 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64; { self = [super init]; if (self) { - _options = options; + [self setOptions:options]; _loading = false; - - mbgl::DefaultFileSource *mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource; - _mbglThreadPool = mbgl::sharedThreadPool(); - - std::string styleURL = std::string([options.styleURL.absoluteString UTF8String]); - - // Size; taking into account the minimum texture size for OpenGL ES - // For non retina screens the ratio is 1:1 MGLSnapshotterMinimumPixelSize - mbgl::Size size = { - static_cast(MAX(options.size.width, MGLSnapshotterMinimumPixelSize)), - static_cast(MAX(options.size.height, MGLSnapshotterMinimumPixelSize)) - }; - - float pixelRatio = MAX(options.scale, 1); - - // Camera options - mbgl::CameraOptions cameraOptions; - if (CLLocationCoordinate2DIsValid(options.camera.centerCoordinate)) { - cameraOptions.center = MGLLatLngFromLocationCoordinate2D(options.camera.centerCoordinate); - } - cameraOptions.angle = MAX(0, options.camera.heading) * mbgl::util::DEG2RAD; - cameraOptions.zoom = MAX(0, options.zoomLevel); - cameraOptions.pitch = MAX(0, options.camera.pitch); - - // Region - mbgl::optional coordinateBounds; - if (!MGLCoordinateBoundsIsEmpty(options.coordinateBounds)) { - coordinateBounds = MGLLatLngBoundsFromCoordinateBounds(options.coordinateBounds); - } - - // Create the snapshotter - _mbglMapSnapshotter = std::make_unique(*mbglFileSource, *_mbglThreadPool, styleURL, size, pixelRatio, cameraOptions, coordinateBounds); + } return self; } @@ -437,81 +406,40 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64; _mbglMapSnapshotter.reset(); } -- (NSURL *)styleURL -{ - NSString *styleURLString = @(_mbglMapSnapshotter->getStyleURL().c_str()); - return styleURLString.length ? [NSURL URLWithString:styleURLString] : nil; -} - -- (void)setStyleURL:(NSURL *)url -{ - _mbglMapSnapshotter->setStyleURL(std::string([url.absoluteString UTF8String])); -} - -- (CGSize)size -{ - mbgl::Size size = _mbglMapSnapshotter->getSize(); - return CGSizeMake(size.width, size.height); -} - -- (void)setSize:(CGSize)size -{ - _mbglMapSnapshotter->setSize({ - static_cast(MAX(size.width, MGLSnapshotterMinimumPixelSize)), - static_cast(MAX(size.height, MGLSnapshotterMinimumPixelSize)) - }); -} - -- (MGLMapCamera *)camera -{ - mbgl::CameraOptions cameraOptions = _mbglMapSnapshotter->getCameraOptions(); - CGFloat pitch = *cameraOptions.pitch; - CLLocationDirection heading = mbgl::util::wrap(*cameraOptions.angle, 0., 360.); - CLLocationDistance distance = MGLAltitudeForZoomLevel(*cameraOptions.zoom, pitch, cameraOptions.center->latitude(), [self size]); - return [MGLMapCamera cameraLookingAtCenterCoordinate:MGLLocationCoordinate2DFromLatLng(*cameraOptions.center) - fromDistance:distance - pitch:pitch - heading:heading]; -} - -- (void)setCamera:(MGLMapCamera *)camera +- (void)setOptions:(MGLMapSnapshotOptions *)options { + _options = options; + mbgl::DefaultFileSource *mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource; + _mbglThreadPool = mbgl::sharedThreadPool(); + + std::string styleURL = std::string([options.styleURL.absoluteString UTF8String]); + + // Size; taking into account the minimum texture size for OpenGL ES + // For non retina screens the ratio is 1:1 MGLSnapshotterMinimumPixelSize + mbgl::Size size = { + static_cast(MAX(options.size.width, MGLSnapshotterMinimumPixelSize)), + static_cast(MAX(options.size.height, MGLSnapshotterMinimumPixelSize)) + }; + + float pixelRatio = MAX(options.scale, 1); + + // Camera options mbgl::CameraOptions cameraOptions; - CLLocationCoordinate2D center; - if (CLLocationCoordinate2DIsValid(camera.centerCoordinate)) { - cameraOptions.center = MGLLatLngFromLocationCoordinate2D(camera.centerCoordinate); - center = camera.centerCoordinate; - } else { - // Center is optional, but always set. - center = MGLLocationCoordinate2DFromLatLng(*_mbglMapSnapshotter->getCameraOptions().center); + if (CLLocationCoordinate2DIsValid(options.camera.centerCoordinate)) { + cameraOptions.center = MGLLatLngFromLocationCoordinate2D(options.camera.centerCoordinate); } + cameraOptions.angle = MAX(0, options.camera.heading) * mbgl::util::DEG2RAD; + cameraOptions.zoom = MAX(0, options.zoomLevel); + cameraOptions.pitch = MAX(0, options.camera.pitch); - cameraOptions.angle = MAX(0, camera.heading) * mbgl::util::DEG2RAD; - cameraOptions.zoom = MAX(0, MGLZoomLevelForAltitude(camera.altitude, camera.pitch, center.latitude, [self size])); - cameraOptions.pitch = MAX(0, camera.pitch); -} - -- (double)zoomLevel -{ - mbgl::CameraOptions cameraOptions = _mbglMapSnapshotter->getCameraOptions(); - return MGLAltitudeForZoomLevel(*cameraOptions.zoom, *cameraOptions.pitch, cameraOptions.center->latitude(), [self size]); -} - -- (void)setZoomLevel:(double)zoomLevel -{ - mbgl::CameraOptions cameraOptions = _mbglMapSnapshotter->getCameraOptions(); - cameraOptions.zoom = zoomLevel; - _mbglMapSnapshotter->setCameraOptions(cameraOptions); -} - -- (MGLCoordinateBounds)coordinateBounds -{ - return MGLCoordinateBoundsFromLatLngBounds(_mbglMapSnapshotter->getRegion()); -} - -- (void)setCoordinateBounds:(MGLCoordinateBounds)coordinateBounds -{ - _mbglMapSnapshotter->setRegion(MGLLatLngBoundsFromCoordinateBounds(coordinateBounds)); + // Region + mbgl::optional coordinateBounds; + if (!MGLCoordinateBoundsIsEmpty(options.coordinateBounds)) { + coordinateBounds = MGLLatLngBoundsFromCoordinateBounds(options.coordinateBounds); + } + + // Create the snapshotter + _mbglMapSnapshotter = std::make_unique(*mbglFileSource, *_mbglThreadPool, styleURL, size, pixelRatio, cameraOptions, coordinateBounds); } @end -- cgit v1.2.1