[ios, macos] Remove duplicated variables between MGLMapSnapshotOptions and MGLMapSnapshotter
This commit is contained in:
committed by
Fabian Guerra Soto
parent
7f5dfb16bc
commit
f644d188be
@@ -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.
|
||||
The options to use when generating a map snapshot.
|
||||
*/
|
||||
@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.
|
||||
*/
|
||||
@property (nonatomic) CGSize size;
|
||||
@property (nonatomic) MGLMapSnapshotOptions *options;
|
||||
|
||||
/**
|
||||
Indicates whether a snapshot is currently being generated.
|
||||
|
||||
@@ -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<uint32_t>(MAX(options.size.width, MGLSnapshotterMinimumPixelSize)),
|
||||
static_cast<uint32_t>(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<mbgl::LatLngBounds> coordinateBounds;
|
||||
if (!MGLCoordinateBoundsIsEmpty(options.coordinateBounds)) {
|
||||
coordinateBounds = MGLLatLngBoundsFromCoordinateBounds(options.coordinateBounds);
|
||||
}
|
||||
|
||||
// Create the snapshotter
|
||||
_mbglMapSnapshotter = std::make_unique<mbgl::MapSnapshotter>(*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<uint32_t>(MAX(size.width, MGLSnapshotterMinimumPixelSize)),
|
||||
static_cast<uint32_t>(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<uint32_t>(MAX(options.size.width, MGLSnapshotterMinimumPixelSize)),
|
||||
static_cast<uint32_t>(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);
|
||||
|
||||
// Region
|
||||
mbgl::optional<mbgl::LatLngBounds> coordinateBounds;
|
||||
if (!MGLCoordinateBoundsIsEmpty(options.coordinateBounds)) {
|
||||
coordinateBounds = MGLLatLngBoundsFromCoordinateBounds(options.coordinateBounds);
|
||||
}
|
||||
|
||||
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));
|
||||
// Create the snapshotter
|
||||
_mbglMapSnapshotter = std::make_unique<mbgl::MapSnapshotter>(*mbglFileSource, *_mbglThreadPool, styleURL, size, pixelRatio, cameraOptions, coordinateBounds);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user