From 557b8afb7c310a6330f741ca0f38fcec098f3156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Thu, 29 Oct 2015 12:23:50 -0700 Subject: [core][iOS] Source iOS styles from default_styles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moved mbgl::util::default_styles to a more appropriate location, where iOS platform code can also find it. Moved -[MGLMapView bundledStyleURLs] (which is now deprecated) and the style switcher in iosapp to default_styles. Added a collection of convenience methods for getting style URLs. It makes little sense to layer an enum atop this, as MapKit does, because MGLMapView styles aren’t limited to this set. A good analogy is UIColor. This also makes for a good entry point for future runtime styling APIs. Introduced independent constants for each default style, because it’s more common to need access to a particular style than to iterate over them. This fact is apparent in the MGLStyle class, which now uses macros and assertions to ensure that it’s kept up-to-date with changes in default_styles. /ref #1462 --- ios/app/MBXViewController.mm | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) (limited to 'ios/app/MBXViewController.mm') diff --git a/ios/app/MBXViewController.mm b/ios/app/MBXViewController.mm index c8a305b3c3..6380406eec 100644 --- a/ios/app/MBXViewController.mm +++ b/ios/app/MBXViewController.mm @@ -1,25 +1,12 @@ #import "MBXViewController.h" #import +#import #import static UIColor *const kTintColor = [UIColor colorWithRed:0.120 green:0.550 blue:0.670 alpha:1.000]; -static struct MBXStyle { - NSString *name; - NSString *displayName; -} MBXAvailableStyles[] = { - {@"streets", @"Streets"}, - {@"emerald", @"Emerald"}, - {@"light", @"Light"}, - {@"dark", @"Dark"}, - {@"satellite", @"Satellite"}, - {@"satellite-hybrid", @"Hybrid"}, -}; - -static NSUInteger const kStyleVersion = 8; - @interface MBXViewController () @property (nonatomic) MGLMapView *mapView; @@ -79,7 +66,7 @@ static NSUInteger const kStyleVersion = 8; UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom]; [titleButton setFrame:CGRectMake(0, 0, 150, 40)]; - [titleButton setTitle:MBXAvailableStyles[self.styleIndex].displayName forState:UIControlStateNormal]; + [titleButton setTitle:@(mbgl::util::default_styles::orderedStyles[self.styleIndex].name) forState:UIControlStateNormal]; [titleButton setTitleColor:kTintColor forState:UIControlStateNormal]; [titleButton addTarget:self action:@selector(cycleStyles) forControlEvents:UIControlEventTouchUpInside]; self.navigationItem.titleView = titleButton; @@ -323,14 +310,11 @@ static NSUInteger const kStyleVersion = 8; { UIButton *titleButton = (UIButton *)self.navigationItem.titleView; - self.styleIndex = (self.styleIndex + 1) % (sizeof(MBXAvailableStyles) / sizeof(MBXAvailableStyles[0])); + self.styleIndex = (self.styleIndex + 1) % mbgl::util::default_styles::numOrderedStyles; - self.mapView.styleURL = [NSURL URLWithString: - [NSString stringWithFormat:@"mapbox://styles/mapbox/%@-v%lu", - MBXAvailableStyles[self.styleIndex].name, - (unsigned long)kStyleVersion]]; + self.mapView.styleURL = [NSURL URLWithString:@(mbgl::util::default_styles::orderedStyles[self.styleIndex].url)]; - [titleButton setTitle:MBXAvailableStyles[self.styleIndex].displayName forState:UIControlStateNormal]; + [titleButton setTitle:@(mbgl::util::default_styles::orderedStyles[self.styleIndex].name) forState:UIControlStateNormal]; } - (void)locateUser -- cgit v1.2.1