Added API for initializing with bundled style

As a best practice for the beta and a workaround for #1014.

Also reversed the argument order of the existing init method. Reads better this way, but you’ll likely have to change your initialization to match the new signatures.
This commit is contained in:
Minh Nguyễn
2015-03-17 16:25:06 -07:00
parent 1ce51a17e7
commit 3d195b467a
2 changed files with 24 additions and 4 deletions

View File

@@ -16,10 +16,17 @@
/** Initialize a map view with a given frame, style, and access token.
* @param frame The frame with which to initialize the map view.
* @param styleJSON The map stylesheet as JSON text.
* @param accessToken A Mapbox API access token.
* @param styleJSON The map stylesheet as JSON text.
* @return An initialized map view, or `nil` if the map view was unable to be initialized. */
- (instancetype)initWithFrame:(CGRect)frame styleJSON:(NSString *)styleJSON accessToken:(NSString *)accessToken;
- (instancetype)initWithFrame:(CGRect)frame accessToken:(NSString *)accessToken styleJSON:(NSString *)styleJSON;
/** Initialize a map view with a given frame, bundled style name, and access token.
* @param frame The frame with which to initialize the map view.
* @param accessToken A Mapbox API access token.
* @param styleName The map style name to use.
* @return An initialized map view, or `nil` if the map view was unable to be initialized. */
- (instancetype)initWithFrame:(CGRect)frame accessToken:(NSString *)accessToken bundledStyleNamed:(NSString *)styleName;
/** Initialize a map view with a given frame, the default style, and an access token.
* @param frame The frame with which to initialize the map view.

View File

@@ -113,7 +113,7 @@ MBGLView *mbglView = nullptr;
mbgl::SQLiteCache *mbglFileCache = nullptr;
mbgl::DefaultFileSource *mbglFileSource = nullptr;
- (instancetype)initWithFrame:(CGRect)frame styleJSON:(NSString *)styleJSON accessToken:(NSString *)accessToken
- (instancetype)initWithFrame:(CGRect)frame accessToken:(NSString *)accessToken styleJSON:(NSString *)styleJSON
{
self = [super initWithFrame:frame];
@@ -133,9 +133,22 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
return self;
}
- (instancetype)initWithFrame:(CGRect)frame accessToken:(NSString *)accessToken bundledStyleNamed:(NSString *)styleName
{
self = [super initWithFrame:frame];
if (self && [self commonInit])
{
if (accessToken) [self setAccessToken:accessToken];
if (styleName) [self useBundledStyleNamed:styleName];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame accessToken:(NSString *)accessToken
{
return [self initWithFrame:frame styleJSON:nil accessToken:accessToken];
return [self initWithFrame:frame accessToken:accessToken styleJSON:nil];
}
- (instancetype)initWithCoder:(NSCoder *)decoder