63 lines
2.3 KiB
Plaintext
63 lines
2.3 KiB
Plaintext
#import "MGLTilePyramidDownloadRegion.h"
|
|
|
|
#import "MGLDownloadRegion_Private.h"
|
|
#import "MGLGeometry_Private.h"
|
|
#import "MGLStyle.h"
|
|
|
|
@interface MGLTilePyramidDownloadRegion () <MGLDownloadRegion_Private>
|
|
|
|
@end
|
|
|
|
@implementation MGLTilePyramidDownloadRegion {
|
|
NSURL *_styleURL;
|
|
}
|
|
|
|
@synthesize styleURL = _styleURL;
|
|
|
|
- (instancetype)init {
|
|
[NSException raise:@"Method unavailable"
|
|
format:
|
|
@"-[MGLTilePyramidDownloadRegion init] is unavailable. "
|
|
@"Use -initWithStyleURL:bounds:fromZoomLevel:toZoomLevel: instead."];
|
|
return nil;
|
|
}
|
|
|
|
- (instancetype)initWithStyleURL:(NSURL *)styleURL bounds:(MGLCoordinateBounds)bounds fromZoomLevel:(double)minimumZoomLevel toZoomLevel:(double)maximumZoomLevel {
|
|
if (self = [super init]) {
|
|
if (!styleURL) {
|
|
styleURL = [MGLStyle streetsStyleURL];
|
|
}
|
|
|
|
if (!styleURL.scheme) {
|
|
// Assume a relative path into the application bundle.
|
|
styleURL = [NSURL URLWithString:[@"asset://" stringByAppendingString:styleURL.absoluteString]];
|
|
}
|
|
|
|
_styleURL = styleURL;
|
|
_bounds = bounds;
|
|
_minimumZoomLevel = minimumZoomLevel;
|
|
_maximumZoomLevel = maximumZoomLevel;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initWithOfflineRegionDefinition:(const mbgl::OfflineRegionDefinition &)definition {
|
|
NSURL *styleURL = [NSURL URLWithString:@(definition.styleURL.c_str())];
|
|
MGLCoordinateBounds bounds = MGLCoordinateBoundsFromLatLngBounds(definition.bounds);
|
|
return [self initWithStyleURL:styleURL bounds:bounds fromZoomLevel:definition.minZoom toZoomLevel:definition.maxZoom];
|
|
}
|
|
|
|
- (const mbgl::OfflineRegionDefinition)offlineRegionDefinition {
|
|
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
|
|
const float scaleFactor = [UIScreen instancesRespondToSelector:@selector(nativeScale)] ? [[UIScreen mainScreen] nativeScale] : [[UIScreen mainScreen] scale];
|
|
#elif TARGET_OS_MAC
|
|
const float scaleFactor = [NSScreen mainScreen].backingScaleFactor;
|
|
#endif
|
|
return mbgl::OfflineTilePyramidRegionDefinition(_styleURL.absoluteString.UTF8String,
|
|
MGLLatLngBoundsFromCoordinateBounds(_bounds),
|
|
_minimumZoomLevel, _maximumZoomLevel,
|
|
scaleFactor);
|
|
}
|
|
|
|
@end
|