summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-04-07 00:58:23 -0400
committerMinh Nguyễn <mxn@1ec5.org>2016-04-07 00:58:23 -0400
commit3671765a517c7faf8f7aa52e81e7244389ac304b (patch)
treec077854c3543f4776e470f71a138363798f38990 /platform
parentcee1b0b526dbec0dea9c4daaac94f333395062e2 (diff)
downloadqtlocation-mapboxgl-3671765a517c7faf8f7aa52e81e7244389ac304b.tar.gz
[ios] Converted MBXViewController to Objective-C
Converted MBXViewController from Objective-C++ to Objective-C. In the process, the dependency on default_styles.hpp was replaced by a hardcoded list of style URLs along with runtime assertions that the list of styles is the right length.
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/app/MBXViewController.m (renamed from platform/ios/app/MBXViewController.mm)73
-rw-r--r--platform/ios/app/mapboxgl-app.gypi2
2 files changed, 57 insertions, 18 deletions
diff --git a/platform/ios/app/MBXViewController.mm b/platform/ios/app/MBXViewController.m
index 9a047a0ee2..f8f2399e23 100644
--- a/platform/ios/app/MBXViewController.mm
+++ b/platform/ios/app/MBXViewController.m
@@ -3,12 +3,11 @@
#import "MBXOfflinePacksTableViewController.h"
#import <Mapbox/Mapbox.h>
-#import "../../../include/mbgl/util/default_styles.hpp"
#import <CoreLocation/CoreLocation.h>
#import <OpenGLES/ES2/gl.h>
+#import <objc/runtime.h>
-static UIColor *const kTintColor = [UIColor colorWithRed:0.120 green:0.550 blue:0.670 alpha:1.000];
static NSString * const kCustomCalloutTitle = @"Custom Callout";
static const CLLocationCoordinate2D WorldTourDestinations[] = {
@@ -21,7 +20,7 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
@interface MBXViewController () <UIActionSheetDelegate, MGLMapViewDelegate>
@property (nonatomic) IBOutlet MGLMapView *mapView;
-@property (nonatomic) NSUInteger styleIndex;
+@property (nonatomic) NSInteger styleIndex;
@end
@@ -42,6 +41,8 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
@"MBXShowsUserLocation": @NO,
@"MBXDebug": @NO,
}];
+
+
}
}
@@ -53,11 +54,8 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(restoreState:) name:UIApplicationWillEnterForegroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveState:) name:UIApplicationWillTerminateNotification object:nil];
- self.styleIndex = 0;
- self.mapView.styleURL = [NSURL URLWithString:@(mbgl::util::default_styles::orderedStyles[self.styleIndex].url)];
-
- UIButton *titleButton = (UIButton *)self.navigationItem.titleView;
- [titleButton setTitle:@(mbgl::util::default_styles::orderedStyles[self.styleIndex].name) forState:UIControlStateNormal];
+ self.styleIndex = -1;
+ [self cycleStyles:self];
[self restoreState:nil];
}
@@ -97,7 +95,7 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
}
}
-- (NSUInteger)supportedInterfaceOrientations
+- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
@@ -355,10 +353,10 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
vertexShader = glCreateShader(GL_VERTEX_SHADER);
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
- glShaderSource(vertexShader, 1, &vertexShaderSource, nullptr);
+ glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
glCompileShader(vertexShader);
glAttachShader(program, vertexShader);
- glShaderSource(fragmentShader, 1, &fragmentShaderSource, nullptr);
+ glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
glCompileShader(fragmentShader);
glAttachShader(program, fragmentShader);
glLinkProgram(program);
@@ -427,13 +425,54 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
- (IBAction)cycleStyles:(__unused id)sender
{
- UIButton *titleButton = (UIButton *)self.navigationItem.titleView;
-
- self.styleIndex = (self.styleIndex + 1) % mbgl::util::default_styles::numOrderedStyles;
-
- self.mapView.styleURL = [NSURL URLWithString:@(mbgl::util::default_styles::orderedStyles[self.styleIndex].url)];
+ static NSArray *styleNames;
+ static NSArray *styleURLs;
+
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ styleNames = @[
+ @"Streets",
+ @"Emerald",
+ @"Light",
+ @"Dark",
+ @"Satellite",
+ @"Hybrid",
+ ];
+ styleURLs = @[
+ [MGLStyle streetsStyleURL],
+ [MGLStyle emeraldStyleURL],
+ [MGLStyle lightStyleURL],
+ [MGLStyle darkStyleURL],
+ [MGLStyle satelliteStyleURL],
+ [MGLStyle hybridStyleURL],
+ ];
+ NSAssert(styleNames.count == styleURLs.count, @"Style names and URLs don’t match.");
+
+ // Make sure defaultStyleURLs is up-to-date.
+ unsigned numMethods = 0;
+ Method *methods = class_copyMethodList(object_getClass([MGLStyle class]), &numMethods);
+ unsigned numStyleURLMethods = 0;
+ for (NSUInteger i; i < numMethods; i++) {
+ Method method = methods[i];
+ if (method_getNumberOfArguments(method) == 2 /* _cmd, self */) {
+ SEL selector = method_getName(method);
+ NSString *name = @(sel_getName(selector));
+ if ([name rangeOfString:@"StyleURL"].location != NSNotFound) {
+ numStyleURLMethods += 1;
+ }
+ }
+ }
+ NSAssert(numStyleURLMethods == styleNames.count,
+ @"MGLStyle provides %u default styles but iosapp only knows about %lu of them.",
+ numStyleURLMethods, (unsigned long)styleNames.count);
+ });
+
+ self.styleIndex = (self.styleIndex + 1) % styleNames.count;
- [titleButton setTitle:@(mbgl::util::default_styles::orderedStyles[self.styleIndex].name) forState:UIControlStateNormal];
+ self.mapView.styleURL = styleURLs[self.styleIndex];
+
+ UIButton *titleButton = (UIButton *)self.navigationItem.titleView;
+ [titleButton setTitle:styleNames[self.styleIndex] forState:UIControlStateNormal];
}
- (IBAction)locateUser:(__unused id)sender
diff --git a/platform/ios/app/mapboxgl-app.gypi b/platform/ios/app/mapboxgl-app.gypi
index c154669485..864755829f 100644
--- a/platform/ios/app/mapboxgl-app.gypi
+++ b/platform/ios/app/mapboxgl-app.gypi
@@ -32,7 +32,7 @@
'MBXOfflinePacksTableViewController.h',
'MBXOfflinePacksTableViewController.m',
'MBXViewController.h',
- 'MBXViewController.mm',
+ 'MBXViewController.m',
],
'xcode_settings': {