From 3d195b467af2901d0c1a5f2103563dc0a2108c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 17 Mar 2015 16:25:06 -0700 Subject: [PATCH] Added API for initializing with bundled style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- include/mbgl/ios/MGLMapView.h | 11 +++++++++-- platform/ios/MGLMapView.mm | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/mbgl/ios/MGLMapView.h b/include/mbgl/ios/MGLMapView.h index f95434026..481e878ed 100644 --- a/include/mbgl/ios/MGLMapView.h +++ b/include/mbgl/ios/MGLMapView.h @@ -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. diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index 0d530ca1c..281755a4c 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -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