summaryrefslogtreecommitdiff
path: root/platform/ios/app/MBXViewController.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/ios/app/MBXViewController.mm')
-rw-r--r--platform/ios/app/MBXViewController.mm112
1 files changed, 36 insertions, 76 deletions
diff --git a/platform/ios/app/MBXViewController.mm b/platform/ios/app/MBXViewController.mm
index af4e425841..548a5e7100 100644
--- a/platform/ios/app/MBXViewController.mm
+++ b/platform/ios/app/MBXViewController.mm
@@ -19,7 +19,7 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
@interface MBXViewController () <UIActionSheetDelegate, MGLMapViewDelegate>
-@property (nonatomic) MGLMapView *mapView;
+@property (nonatomic) IBOutlet MGLMapView *mapView;
@property (nonatomic) NSUInteger styleIndex;
@end
@@ -44,94 +44,54 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
}
}
-- (id)init
-{
- self = [super init];
-
- if (self)
- {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveState:) name:UIApplicationDidEnterBackgroundNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(restoreState:) name:UIApplicationWillEnterForegroundNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveState:) name:UIApplicationWillTerminateNotification object:nil];
- }
-
- return self;
-}
-
- (void)viewDidLoad
{
[super viewDidLoad];
-
- self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds];
- self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- self.mapView.delegate = self;
- [self.view addSubview:self.mapView];
-
- self.view.tintColor = kTintColor;
- self.navigationController.navigationBar.tintColor = kTintColor;
- self.mapView.tintColor = kTintColor;
-
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"settings.png"]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(showSettings)];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveState:) name:UIApplicationDidEnterBackgroundNotification object:nil];
+ [[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;
- UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [titleButton setFrame:CGRectMake(0, 0, 150, 40)];
+ UIButton *titleButton = (UIButton *)self.navigationItem.titleView;
[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;
-
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"TrackingLocationOffMask.png"]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(locateUser)];
-
- [self.mapView addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]];
[self restoreState:nil];
}
- (void)saveState:(__unused NSNotification *)notification
{
- if (self.mapView)
- {
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- NSData *archivedCamera = [NSKeyedArchiver archivedDataWithRootObject:self.mapView.camera];
- [defaults setObject:archivedCamera forKey:@"MBXCamera"];
- [defaults setInteger:self.mapView.userTrackingMode forKey:@"MBXUserTrackingMode"];
- [defaults setBool:self.mapView.showsUserLocation forKey:@"MBXShowsUserLocation"];
- [defaults setInteger:self.mapView.debugMask forKey:@"MBXDebugMask"];
- [defaults synchronize];
- }
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+ NSData *archivedCamera = [NSKeyedArchiver archivedDataWithRootObject:self.mapView.camera];
+ [defaults setObject:archivedCamera forKey:@"MBXCamera"];
+ [defaults setInteger:self.mapView.userTrackingMode forKey:@"MBXUserTrackingMode"];
+ [defaults setBool:self.mapView.showsUserLocation forKey:@"MBXShowsUserLocation"];
+ [defaults setInteger:self.mapView.debugMask forKey:@"MBXDebugMask"];
+ [defaults synchronize];
}
- (void)restoreState:(__unused NSNotification *)notification
{
- if (self.mapView) {
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- NSData *archivedCamera = [defaults objectForKey:@"MBXCamera"];
- MGLMapCamera *camera = archivedCamera ? [NSKeyedUnarchiver unarchiveObjectWithData:archivedCamera] : nil;
- if (camera)
- {
- self.mapView.camera = camera;
- }
- NSInteger uncheckedTrackingMode = [defaults integerForKey:@"MBXUserTrackingMode"];
- if (uncheckedTrackingMode >= 0 &&
- (NSUInteger)uncheckedTrackingMode >= MGLUserTrackingModeNone &&
- (NSUInteger)uncheckedTrackingMode <= MGLUserTrackingModeFollowWithCourse)
- {
- self.mapView.userTrackingMode = (MGLUserTrackingMode)uncheckedTrackingMode;
- }
- self.mapView.showsUserLocation = [defaults boolForKey:@"MBXShowsUserLocation"];
- NSInteger uncheckedDebugMask = [defaults integerForKey:@"MBXDebugMask"];
- if (uncheckedDebugMask >= 0)
- {
- self.mapView.debugMask = (MGLMapDebugMaskOptions)uncheckedDebugMask;
- }
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+ NSData *archivedCamera = [defaults objectForKey:@"MBXCamera"];
+ MGLMapCamera *camera = archivedCamera ? [NSKeyedUnarchiver unarchiveObjectWithData:archivedCamera] : nil;
+ if (camera)
+ {
+ self.mapView.camera = camera;
+ }
+ NSInteger uncheckedTrackingMode = [defaults integerForKey:@"MBXUserTrackingMode"];
+ if (uncheckedTrackingMode >= 0 &&
+ (NSUInteger)uncheckedTrackingMode >= MGLUserTrackingModeNone &&
+ (NSUInteger)uncheckedTrackingMode <= MGLUserTrackingModeFollowWithCourse)
+ {
+ self.mapView.userTrackingMode = (MGLUserTrackingMode)uncheckedTrackingMode;
+ }
+ self.mapView.showsUserLocation = [defaults boolForKey:@"MBXShowsUserLocation"];
+ NSInteger uncheckedDebugMask = [defaults integerForKey:@"MBXDebugMask"];
+ if (uncheckedDebugMask >= 0)
+ {
+ self.mapView.debugMask = (MGLMapDebugMaskOptions)uncheckedDebugMask;
}
}
@@ -142,7 +102,7 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
#pragma mark - Actions
-- (void)showSettings
+- (IBAction)showSettings:(__unused id)sender
{
MGLMapDebugMaskOptions debugMask = self.mapView.debugMask;
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Map Settings"
@@ -441,7 +401,7 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
[self.mapView showAnnotations:@[annotation] animated:YES];
}
-- (void)handleLongPress:(UILongPressGestureRecognizer *)longPress
+- (IBAction)handleLongPress:(UILongPressGestureRecognizer *)longPress
{
if (longPress.state == UIGestureRecognizerStateBegan)
{
@@ -455,7 +415,7 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
}
}
-- (void)cycleStyles
+- (IBAction)cycleStyles:(__unused id)sender
{
UIButton *titleButton = (UIButton *)self.navigationItem.titleView;
@@ -466,7 +426,7 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
[titleButton setTitle:@(mbgl::util::default_styles::orderedStyles[self.styleIndex].name) forState:UIControlStateNormal];
}
-- (void)locateUser
+- (IBAction)locateUser:(__unused id)sender
{
MGLUserTrackingMode nextMode;
switch (self.mapView.userTrackingMode) {