From c0fb9399267eb2273be88bd441099d700dfb1265 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Wed, 14 Sep 2016 11:32:02 -0700 Subject: [PATCH] [ios, macos] Introduce MGLTileSet This reverts a previous change to vector / raster sources that added initializers to those classes so they could take certain tileset properties and create their own mbgl::Tileset objects. Now, a new MGLTileSet class that wraps all available core Tileset options can be created and passed into the sources. The sources pass that tileset object along to core. --- platform/darwin/src/MGLRasterSource.h | 9 +-- platform/darwin/src/MGLRasterSource.mm | 16 ++--- platform/darwin/src/MGLTileSet.h | 24 ++++++++ platform/darwin/src/MGLTileSet.mm | 72 ++++++++++++++++++++++ platform/darwin/src/MGLTileSet_Private.h | 9 +++ platform/darwin/src/MGLVectorSource.h | 8 +-- platform/darwin/src/MGLVectorSource.mm | 15 ++--- platform/ios/app/MBXViewController.m | 4 +- platform/ios/ios.xcodeproj/project.pbxproj | 20 +++++- platform/ios/src/Mapbox.h | 1 + 10 files changed, 145 insertions(+), 33 deletions(-) create mode 100644 platform/darwin/src/MGLTileSet.h create mode 100644 platform/darwin/src/MGLTileSet.mm create mode 100644 platform/darwin/src/MGLTileSet_Private.h diff --git a/platform/darwin/src/MGLRasterSource.h b/platform/darwin/src/MGLRasterSource.h index 52bed1b36e7..5a522e37a4f 100644 --- a/platform/darwin/src/MGLRasterSource.h +++ b/platform/darwin/src/MGLRasterSource.h @@ -1,19 +1,20 @@ #import "MGLSource.h" #import "MGLTypes.h" +@class MGLTileSet; + NS_ASSUME_NONNULL_BEGIN @interface MGLRasterSource : MGLSource @property (nonatomic, readonly, copy) NSURL *URL; @property (nonatomic, readonly, assign) CGFloat tileSize; -@property (nonatomic, readonly, copy) NS_ARRAY_OF(NSString *) *tileURLTemplates; -@property (nonatomic, readonly) uint8_t minimumZoomLevel; -@property (nonatomic, readonly) uint8_t maximumZoomLevel; +@property (nonatomic, readonly, nullable) MGLTileSet *tileSet; - (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL *)url tileSize:(CGFloat)tileSize; -- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier tileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates minimumZoomLevel:(NSUInteger)minimumZoomLevel maximumZoomLevel:(NSUInteger)maximumZoomLevel; +- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier tileSize:(CGFloat)tileSize tileSet:(MGLTileSet *)tileSet; + @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLRasterSource.mm b/platform/darwin/src/MGLRasterSource.mm index 73c9476623e..9e8028ef936 100644 --- a/platform/darwin/src/MGLRasterSource.mm +++ b/platform/darwin/src/MGLRasterSource.mm @@ -1,6 +1,7 @@ #import "MGLRasterSource.h" #import "MGLSource_Private.h" +#import "MGLTileSet_Private.h" #include @@ -15,13 +16,12 @@ - (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL return self; } -- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier tileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates minimumZoomLevel:(NSUInteger)minimumZoomLevel maximumZoomLevel:(NSUInteger)maximumZoomLevel +- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier tileSize:(CGFloat)tileSize tileSet:(MGLTileSet *)tileSet; { if (self = [super initWithSourceIdentifier:sourceIdentifier]) { - _tileURLTemplates = tileURLTemplates; - _minimumZoomLevel = minimumZoomLevel; - _maximumZoomLevel = maximumZoomLevel; + _tileSize = tileSize; + _tileSet = tileSet; } return self; } @@ -38,13 +38,7 @@ - (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier tileURLTem } else { - mbgl::Tileset tileSource; - tileSource.zoomRange = mbgl::Range(self.minimumZoomLevel, self.maximumZoomLevel); - for (NSString *tileURLTemplate in self.tileURLTemplates) - { - tileSource.tiles.push_back(tileURLTemplate.UTF8String); - } - source = std::make_unique(self.sourceIdentifier.UTF8String, tileSource, uint16_t(self.tileSize)); + source = std::make_unique(self.sourceIdentifier.UTF8String, self.tileSet.mbglTileset, uint16_t(self.tileSize)); } diff --git a/platform/darwin/src/MGLTileSet.h b/platform/darwin/src/MGLTileSet.h new file mode 100644 index 00000000000..5d051684c5a --- /dev/null +++ b/platform/darwin/src/MGLTileSet.h @@ -0,0 +1,24 @@ +#import +#import "MGLTypes.h" + +NS_ASSUME_NONNULL_BEGIN + +typedef NS_ENUM(NSUInteger, MGLTileSetScheme) { + MGLTileSetSchemeXYZ = 0, + MGLTileSetSchemeTMS +}; + +@interface MGLTileSet : NSObject + +@property (nonatomic, copy) NS_ARRAY_OF(NSString *) *tileURLTemplates; +@property (nonatomic) NSUInteger minimumZoomLevel; +@property (nonatomic) NSUInteger maximumZoomLevel; +@property (nonatomic, copy) NSString *attribution; +@property (nonatomic) MGLTileSetScheme scheme; + +- (instancetype)initWithTileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates; +- (instancetype)initWithTileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates minimumZoomLevel:(NSUInteger)minimumZoomLevel maximumZoomLevel:(NSUInteger)maximumZoomLevel; + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLTileSet.mm b/platform/darwin/src/MGLTileSet.mm new file mode 100644 index 00000000000..bd05bc23170 --- /dev/null +++ b/platform/darwin/src/MGLTileSet.mm @@ -0,0 +1,72 @@ +#import "MGLTileSet.h" + +#include + +@implementation MGLTileSet +{ + BOOL _minimumZoomLevelIsSet; + BOOL _maximumZoomLevelIsSet; +} + +- (instancetype)initWithTileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates +{ + if (self = [super init]) + { + _tileURLTemplates = tileURLTemplates; + } + return self; +} + +- (instancetype)initWithTileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates minimumZoomLevel:(NSUInteger)minimumZoomLevel maximumZoomLevel:(NSUInteger)maximumZoomLevel +{ + if (self = [super init]) + { + _tileURLTemplates = tileURLTemplates; + _minimumZoomLevel = minimumZoomLevel; + _minimumZoomLevelIsSet = YES; + _maximumZoomLevel = maximumZoomLevel; + _maximumZoomLevelIsSet = YES; + } + return self; +} + +- (void)setMinimumZoomLevel:(NSUInteger)minimumZoomLevel +{ + _minimumZoomLevel = minimumZoomLevel; + _minimumZoomLevelIsSet = YES; +} + +- (void)setMaximumZoomLevel:(NSUInteger)maximumZoomLevel +{ + _maximumZoomLevel = maximumZoomLevel; + _maximumZoomLevelIsSet = YES; +} + +- (mbgl::Tileset)mbglTileset +{ + mbgl::Tileset tileset; + + for (NSString *tileURLTemplate in self.tileURLTemplates) + { + tileset.tiles.push_back(tileURLTemplate.UTF8String); + } + + // set the minimum / maximum zoom range to the values specified by this class if they + // were set. otherwise, use the core objects default values + uint8_t minimumZoomLevel = _minimumZoomLevelIsSet ? self.minimumZoomLevel : tileset.zoomRange.min; + uint8_t maximumZoomLevel = _maximumZoomLevelIsSet ? self.maximumZoomLevel : tileset.zoomRange.max; + tileset.zoomRange = mbgl::Range(minimumZoomLevel, maximumZoomLevel); + + if (self.attribution) + { + tileset.attribution = self.attribution.UTF8String; + } + + if (self.scheme == MGLTileSetSchemeTMS) { + tileset.scheme = mbgl::Tileset::Scheme::TMS; + } + + return tileset; +} + +@end diff --git a/platform/darwin/src/MGLTileSet_Private.h b/platform/darwin/src/MGLTileSet_Private.h new file mode 100644 index 00000000000..6a14d428dba --- /dev/null +++ b/platform/darwin/src/MGLTileSet_Private.h @@ -0,0 +1,9 @@ +#import "MGLTileSet.h" + +#include + +@interface MGLTileSet (Private) + +- (mbgl::Tileset)mbglTileset; + +@end \ No newline at end of file diff --git a/platform/darwin/src/MGLVectorSource.h b/platform/darwin/src/MGLVectorSource.h index 1e674f470fe..bcbbf96b922 100644 --- a/platform/darwin/src/MGLVectorSource.h +++ b/platform/darwin/src/MGLVectorSource.h @@ -1,4 +1,5 @@ #import "MGLSource.h" +#import "MGLTileSet.h" #import "MGLTypes.h" NS_ASSUME_NONNULL_BEGIN @@ -12,10 +13,7 @@ NS_ASSUME_NONNULL_BEGIN @interface MGLVectorSource : MGLSource @property (nonatomic, readonly, copy) NSURL *URL; - -@property (nonatomic, readonly, copy) NS_ARRAY_OF(NSString *) *tileURLTemplates; -@property (nonatomic, readonly) uint8_t minimumZoomLevel; -@property (nonatomic, readonly) uint8_t maximumZoomLevel; +@property (nonatomic, readonly, nullable) MGLTileSet *tileSet; /** Initializes and returns a vector source from a remote url. @@ -27,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL *)url; -- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier tileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates minimumZoomLevel:(NSUInteger)minimumZoomLevel maximumZoomLevel:(NSUInteger)maximumZoomLevel; +- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier tileSet:(MGLTileSet *)tileSet; @end diff --git a/platform/darwin/src/MGLVectorSource.mm b/platform/darwin/src/MGLVectorSource.mm index 3de66e3fbc8..aad0f20bc7c 100644 --- a/platform/darwin/src/MGLVectorSource.mm +++ b/platform/darwin/src/MGLVectorSource.mm @@ -1,6 +1,7 @@ #import "MGLVectorSource.h" #import "MGLSource_Private.h" +#import "MGLTileSet_Private.h" #include @@ -17,13 +18,11 @@ - (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL return self; } -- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier tileURLTemplates:(NS_ARRAY_OF(NSString *) *)tileURLTemplates minimumZoomLevel:(NSUInteger)minimumZoomLevel maximumZoomLevel:(NSUInteger)maximumZoomLevel +- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier tileSet:(MGLTileSet *)tileSet { if (self = [super initWithSourceIdentifier:sourceIdentifier]) { - _tileURLTemplates = tileURLTemplates; - _minimumZoomLevel = minimumZoomLevel; - _maximumZoomLevel = maximumZoomLevel; + _tileSet = tileSet; } return self; } @@ -38,13 +37,7 @@ - (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier tileURLTem } else { - mbgl::Tileset tileSource; - tileSource.zoomRange = mbgl::Range(self.minimumZoomLevel, self.maximumZoomLevel); - for (NSString *tileURLTemplate in self.tileURLTemplates) - { - tileSource.tiles.push_back(tileURLTemplate.UTF8String); - } - source = std::make_unique(self.sourceIdentifier.UTF8String, tileSource); + source = std::make_unique(self.sourceIdentifier.UTF8String, self.tileSet.mbglTileset); } return std::move(source); diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index de6faeca2b2..55c11ecb126 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -911,7 +911,9 @@ - (void)mapView:(MGLMapView *)mapView tapOnCalloutForAnnotation:(id