summaryrefslogtreecommitdiff
path: root/platform/ios
diff options
context:
space:
mode:
authorNadia Barbosa <captainbarbosa@users.noreply.github.com>2019-06-13 09:35:41 -0700
committerGitHub <noreply@github.com>2019-06-13 09:35:41 -0700
commit92f282b52dbe45ee8c60d7a5ba2c642688e43cc0 (patch)
tree216eeae3184fdc97f0e045164eb303f0f9ef44b5 /platform/ios
parent6b7d3a16c0e626d2f999e8358c4a0da2af75de87 (diff)
downloadqtlocation-mapboxgl-92f282b52dbe45ee8c60d7a5ba2c642688e43cc0.tar.gz
[iosapp] Introduce map state manager (#14591)
Diffstat (limited to 'platform/ios')
-rw-r--r--platform/ios/app/MBXState.h36
-rw-r--r--platform/ios/app/MBXState.m74
-rw-r--r--platform/ios/app/MBXStateManager.h19
-rw-r--r--platform/ios/app/MBXStateManager.m43
-rw-r--r--platform/ios/app/MBXViewController.m185
-rw-r--r--platform/ios/ios.xcodeproj/project.pbxproj12
6 files changed, 276 insertions, 93 deletions
diff --git a/platform/ios/app/MBXState.h b/platform/ios/app/MBXState.h
new file mode 100644
index 0000000000..7cf064acd8
--- /dev/null
+++ b/platform/ios/app/MBXState.h
@@ -0,0 +1,36 @@
+#import <Foundation/Foundation.h>
+#import <Mapbox/Mapbox.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+FOUNDATION_EXTERN NSString *const MBXCamera;
+FOUNDATION_EXTERN NSString *const MBXShowsUserLocation;
+FOUNDATION_EXTERN NSString *const MBXUserTrackingMode;
+FOUNDATION_EXTERN NSString *const MBXMapShowsHeadingIndicator;
+FOUNDATION_EXTERN NSString *const MBXShowsMapScale;
+FOUNDATION_EXTERN NSString *const MBXShowsZoomLevelOrnament;
+FOUNDATION_EXTERN NSString *const MBXShowsTimeFrameGraph;
+FOUNDATION_EXTERN NSString *const MBXMapFramerateMeasurementEnabled;
+FOUNDATION_EXTERN NSString *const MBXDebugMaskValue;
+FOUNDATION_EXTERN NSString *const MBXDebugLoggingEnabled;
+FOUNDATION_EXTERN NSString *const MBXReuseQueueStatsEnabled;
+
+@interface MBXState : NSObject <NSSecureCoding>
+
+@property (nonatomic, nullable) MGLMapCamera *camera;
+@property (nonatomic) BOOL showsUserLocation;
+@property (nonatomic) MGLUserTrackingMode userTrackingMode;
+@property (nonatomic) BOOL showsUserHeadingIndicator;
+@property (nonatomic) BOOL showsMapScale;
+@property (nonatomic) BOOL showsZoomLevelOrnament;
+@property (nonatomic) BOOL showsTimeFrameGraph;
+@property (nonatomic) BOOL framerateMeasurementEnabled;
+@property (nonatomic) MGLMapDebugMaskOptions debugMask;
+@property (nonatomic) BOOL debugLoggingEnabled;
+@property (nonatomic) BOOL reuseQueueStatsEnabled;
+
+@property (nonatomic, readonly) NSString *debugDescription;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/app/MBXState.m b/platform/ios/app/MBXState.m
new file mode 100644
index 0000000000..49ccd67e8d
--- /dev/null
+++ b/platform/ios/app/MBXState.m
@@ -0,0 +1,74 @@
+#import "MBXState.h"
+
+NSString *const MBXCamera = @"MBXCamera";
+NSString *const MBXUserTrackingMode = @"MBXUserTrackingMode";
+NSString *const MBXShowsUserLocation = @"MBXShowsUserLocation";
+NSString *const MBXDebugMaskValue = @"MBXDebugMaskValue";
+NSString *const MBXShowsZoomLevelOrnament = @"MBXShowsZoomLevelOrnament";
+NSString *const MBXShowsTimeFrameGraph = @"MBXShowsFrameTimeGraph";
+NSString *const MBXDebugLoggingEnabled = @"MGLMapboxMetricsDebugLoggingEnabled";
+NSString *const MBXShowsMapScale = @"MBXMapShowsScale";
+NSString *const MBXMapShowsHeadingIndicator = @"MBXMapShowsHeadingIndicator";
+NSString *const MBXMapFramerateMeasurementEnabled = @"MBXMapFramerateMeasurementEnabled";
+NSString *const MBXReuseQueueStatsEnabled = @"MBXReuseQueueStatsEnabled";
+
+@interface MBXState()
+
+@end
+
+@implementation MBXState
+
+- (void)encodeWithCoder:(NSCoder *)coder
+{
+ [coder encodeObject:_camera forKey:MBXCamera];
+ [coder encodeObject:[NSNumber numberWithInt:_userTrackingMode] forKey:MBXUserTrackingMode];
+ [coder encodeBool:_showsUserLocation forKey:MBXShowsUserLocation];
+ [coder encodeObject:[NSNumber numberWithInt:_debugMask] forKey:MBXDebugMaskValue];
+ [coder encodeBool:_showsZoomLevelOrnament forKey:MBXShowsZoomLevelOrnament];
+ [coder encodeBool:_showsTimeFrameGraph forKey:MBXShowsTimeFrameGraph];
+ [coder encodeBool:_debugLoggingEnabled forKey:MBXDebugLoggingEnabled];
+ [coder encodeBool:_showsMapScale forKey:MBXShowsMapScale];
+ [coder encodeBool:_showsUserHeadingIndicator forKey:MBXMapShowsHeadingIndicator];
+ [coder encodeBool:_framerateMeasurementEnabled forKey:MBXMapFramerateMeasurementEnabled];
+ [coder encodeBool:_reuseQueueStatsEnabled forKey:MBXReuseQueueStatsEnabled];
+}
+
+- (nullable instancetype)initWithCoder:(nonnull NSCoder *)decoder {
+ if (self = [super init]) {
+ MGLMapCamera *decodedCamera = [decoder decodeObjectForKey:MBXCamera];
+ NSNumber *decodedUserTrackingMode = [decoder decodeObjectForKey:MBXUserTrackingMode];
+ BOOL decodedShowsUserLocation = [decoder decodeBoolForKey:MBXShowsUserLocation];
+ NSNumber *decodedDebugMaskOptions = [decoder decodeObjectForKey:MBXDebugMaskValue];
+ BOOL decodedZoomLevelOrnament = [decoder decodeBoolForKey:MBXShowsZoomLevelOrnament];
+ BOOL decodedShowsTimeFrameGraph = [decoder decodeBoolForKey:MBXShowsTimeFrameGraph];
+ BOOL decodedDebugLoggingEnabled = [decoder decodeBoolForKey:MBXDebugLoggingEnabled];
+ BOOL decodedShowsMapScale = [decoder decodeBoolForKey:MBXShowsMapScale];
+ BOOL decodedShowsUserHeadingIndicator = [decoder decodeBoolForKey:MBXMapShowsHeadingIndicator];
+ BOOL decodedFramerateMeasurementEnabled = [decoder decodeBoolForKey:MBXMapFramerateMeasurementEnabled];
+ BOOL decodedReuseQueueStatsEnabled = [decoder decodeBoolForKey:MBXReuseQueueStatsEnabled];
+
+ _camera = decodedCamera;
+ _userTrackingMode = decodedUserTrackingMode.intValue;
+ _showsUserLocation = decodedShowsUserLocation;
+ _debugMask = decodedDebugMaskOptions.intValue;
+ _showsZoomLevelOrnament = decodedZoomLevelOrnament;
+ _showsTimeFrameGraph = decodedShowsTimeFrameGraph;
+ _debugLoggingEnabled = decodedDebugLoggingEnabled;
+ _showsMapScale = decodedShowsMapScale;
+ _showsUserHeadingIndicator = decodedShowsUserHeadingIndicator;
+ _framerateMeasurementEnabled = decodedFramerateMeasurementEnabled;
+ _reuseQueueStatsEnabled = decodedReuseQueueStatsEnabled;
+ }
+
+ return self;
+}
+
++ (BOOL)supportsSecureCoding {
+ return YES;
+}
+
+- (NSString*) debugDescription {
+ return [NSString stringWithFormat:@"Camera: %@\nTracking mode: %lu\nShows user location: %@\nDebug mask value: %lu\nShows zoom level ornament: %@\nShows time frame graph: %@\nDebug logging enabled: %@\nShows map scale: %@\nShows user heading indicator: %@\nFramerate measurement enabled: %@", self.camera, (unsigned long)self.userTrackingMode, (self.showsUserLocation) ? @"YES" : @"NO", (unsigned long)self.debugMask, (self.showsZoomLevelOrnament) ? @"YES" : @"NO", (self.showsTimeFrameGraph) ? @"YES" : @"NO", (self.debugLoggingEnabled) ? @"YES" : @"NO", (self.showsMapScale) ? @"YES" : @"NO", (self.showsUserHeadingIndicator) ? @"YES" : @"NO", (self.framerateMeasurementEnabled) ? @"YES" : @"NO", (self.reuseQueueStatsEnabled) ? @"YES" : @"NO"];
+}
+
+@end
diff --git a/platform/ios/app/MBXStateManager.h b/platform/ios/app/MBXStateManager.h
new file mode 100644
index 0000000000..1a3c8810eb
--- /dev/null
+++ b/platform/ios/app/MBXStateManager.h
@@ -0,0 +1,19 @@
+#import <Foundation/Foundation.h>
+#import "MBXViewController.h"
+@class MBXState;
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface MBXStateManager : NSObject
+
++ (instancetype) sharedManager;
+
+- (MBXState *)currentState;
+
+- (void)saveState:(MBXState*)mapViewController;
+
+- (void)resetState;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/app/MBXStateManager.m b/platform/ios/app/MBXStateManager.m
new file mode 100644
index 0000000000..679a4a075f
--- /dev/null
+++ b/platform/ios/app/MBXStateManager.m
@@ -0,0 +1,43 @@
+#import "MBXStateManager.h"
+#import <Mapbox/Mapbox.h>
+#import "MBXState.h"
+#import "MBXViewController.h"
+
+@interface MBXStateManager()
+
+@property (strong, nonatomic) MBXState *currentState;
+
+@end
+
+@implementation MBXStateManager
+
++ (instancetype) sharedManager {
+ static dispatch_once_t once;
+ static MBXStateManager* sharedManager;
+ dispatch_once(&once, ^{
+ sharedManager = [[self alloc] init];
+ });
+
+ return sharedManager;
+}
+
+- (MBXState*)currentState {
+ NSData *encodedMapState = [[NSUserDefaults standardUserDefaults] objectForKey:@"mapStateKey"];
+ MBXState *currentState = (MBXState *)[NSKeyedUnarchiver unarchiveObjectWithData: encodedMapState];
+
+ return currentState;
+}
+
+- (void)saveState:(MBXState*)mapState {
+ NSData *encodedMapState = [NSKeyedArchiver archivedDataWithRootObject:mapState];
+ [[NSUserDefaults standardUserDefaults] setObject:encodedMapState forKey:@"mapStateKey"];
+ [[NSUserDefaults standardUserDefaults] synchronize];
+}
+
+- (void)resetState {
+ [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"mapStateKey"];
+}
+
+
+
+@end
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index 893cee1cdc..44b8ae2bac 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -8,6 +8,8 @@
#import "LimeGreenStyleLayer.h"
#import "MBXEmbeddedMapViewController.h"
#import "MBXOrnamentsViewController.h"
+#import "MBXStateManager.h"
+#import "MBXState.h"
#import "MBXFrameTimeGraphView.h"
@@ -198,17 +200,18 @@ CLLocationCoordinate2D randomWorldCoordinate() {
@property (nonatomic) IBOutlet MGLMapView *mapView;
+@property (nonatomic) MBXState *currentState;
@property (weak, nonatomic) IBOutlet UIButton *hudLabel;
@property (weak, nonatomic) IBOutlet MBXFrameTimeGraphView *frameTimeGraphView;
@property (nonatomic) NSInteger styleIndex;
-@property (nonatomic) BOOL debugLoggingEnabled;
@property (nonatomic) BOOL customUserLocationAnnnotationEnabled;
@property (nonatomic, getter=isLocalizingLabels) BOOL localizingLabels;
@property (nonatomic) BOOL reuseQueueStatsEnabled;
-@property (nonatomic) BOOL mapInfoHUDEnabled;
@property (nonatomic) BOOL frameTimeGraphEnabled;
@property (nonatomic) BOOL shouldLimitCameraChanges;
@property (nonatomic) BOOL randomWalk;
+@property (nonatomic) BOOL zoomLevelOrnamentEnabled;
+@property (nonatomic) BOOL debugLoggingEnabled;
@property (nonatomic) NSMutableArray<UIWindow *> *helperWindows;
@property (nonatomic) NSMutableArray<UIView *> *contentInsetsOverlays;
@@ -227,27 +230,33 @@ CLLocationCoordinate2D randomWorldCoordinate() {
#pragma mark - Setup & Teardown
-+ (void)initialize
-{
- if (self == [MBXViewController class])
- {
- [[NSUserDefaults standardUserDefaults] registerDefaults:@{
- @"MBXUserTrackingMode": @(MGLUserTrackingModeNone),
- @"MBXShowsUserLocation": @NO,
- @"MBXDebug": @NO,
- }];
- }
-}
-
- (void)viewDidLoad
{
[super viewDidLoad];
- [[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];
+ // Keep track of current map state and debug preferences,
+ // saving and restoring when the application's state changes.
+ self.currentState = [MBXStateManager sharedManager].currentState;
- [self restoreState:nil];
+ if (!self.currentState) {
+ // Create a new state with the below default values
+ self.currentState = [[MBXState alloc] init];
+
+ self.mapView.showsUserHeadingIndicator = YES;
+ self.mapView.showsScale = YES;
+ self.zoomLevelOrnamentEnabled = NO;
+ self.frameTimeGraphEnabled = NO;
+ self.debugLoggingEnabled = YES;
+ } else {
+ // Revert to the previously saved state
+ [self restoreMapState:nil];
+ }
+
+ [self updateHUD];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveCurrentMapState:) name:UIApplicationDidEnterBackgroundNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(restoreMapState:) name:UIApplicationWillEnterForegroundNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveCurrentMapState:) name:UIApplicationWillTerminateNotification object:nil];
if ([MGLAccountManager accessToken].length)
{
@@ -255,9 +264,6 @@ CLLocationCoordinate2D randomWorldCoordinate() {
[self cycleStyles:self];
}
- self.debugLoggingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsDebugLoggingEnabled"];
- self.mapView.showsScale = YES;
- self.mapView.showsUserHeadingIndicator = YES;
self.mapView.experimental_enableFrameRateMeasurement = YES;
self.hudLabel.titleLabel.font = [UIFont monospacedDigitSystemFontOfSize:10 weight:UIFontWeightRegular];
@@ -298,53 +304,6 @@ CLLocationCoordinate2D randomWorldCoordinate() {
}];
}
-- (void)saveState:(__unused NSNotification *)notification
-{
- 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 setBool:self.mapInfoHUDEnabled forKey:@"MBXShowsZoomLevelHUD"];
- [defaults setBool:self.mapInfoHUDEnabled forKey:@"MBXShowsFrameTimeGraph"];
- [defaults synchronize];
-}
-
-- (void)restoreState:(__unused NSNotification *)notification
-{
- 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;
- }
- if ([defaults boolForKey:@"MBXShowsZoomLevelHUD"])
- {
- self.mapInfoHUDEnabled = YES;
- [self updateHUD];
- }
- if ([defaults boolForKey:@"MBXShowsFrameTimeGraph"])
- {
- self.frameTimeGraphEnabled = YES;
- self.frameTimeGraphView.hidden = NO;
- }
-}
-
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
@@ -360,8 +319,6 @@ CLLocationCoordinate2D randomWorldCoordinate() {
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
-
- [self saveState:nil];
}
#pragma mark - Debugging Interface
@@ -405,20 +362,20 @@ CLLocationCoordinate2D randomWorldCoordinate() {
{
case MBXSettingsDebugTools:
[settingsTitles addObjectsFromArray:@[
- @"Reset Position",
- [NSString stringWithFormat:@"%@ Tile Boundaries",
+ @"Reset position",
+ [NSString stringWithFormat:@"%@ tile boundaries",
(debugMask & MGLMapDebugTileBoundariesMask ? @"Hide" :@"Show")],
- [NSString stringWithFormat:@"%@ Tile Info",
+ [NSString stringWithFormat:@"%@ tile info",
(debugMask & MGLMapDebugTileInfoMask ? @"Hide" :@"Show")],
- [NSString stringWithFormat:@"%@ Tile Timestamps",
+ [NSString stringWithFormat:@"%@ tile timestamps",
(debugMask & MGLMapDebugTimestampsMask ? @"Hide" :@"Show")],
- [NSString stringWithFormat:@"%@ Collision Boxes",
+ [NSString stringWithFormat:@"%@ collision boxes",
(debugMask & MGLMapDebugCollisionBoxesMask ? @"Hide" :@"Show")],
- [NSString stringWithFormat:@"%@ Overdraw Visualization",
+ [NSString stringWithFormat:@"%@ overdraw visualization",
(debugMask & MGLMapDebugOverdrawVisualizationMask ? @"Hide" :@"Show")],
- [NSString stringWithFormat:@"%@ Map Info HUD", (_mapInfoHUDEnabled ? @"Hide" :@"Show")],
- [NSString stringWithFormat:@"%@ Frame Time Graph", (_frameTimeGraphEnabled ? @"Hide" :@"Show")],
- [NSString stringWithFormat:@"%@ Reuse Queue Stats", (_reuseQueueStatsEnabled ? @"Hide" :@"Show")]
+ [NSString stringWithFormat:@"%@ zoom level ornament", (self.zoomLevelOrnamentEnabled ? @"Hide" :@"Show")],
+ [NSString stringWithFormat:@"%@ frame time graph", (self.frameTimeGraphEnabled ? @"Hide" :@"Show")],
+ [NSString stringWithFormat:@"%@ reuse queue stats", (self.reuseQueueStatsEnabled ? @"Hide" :@"Show")]
]];
break;
case MBXSettingsAnnotations:
@@ -484,7 +441,7 @@ CLLocationCoordinate2D randomWorldCoordinate() {
@"Ornaments Placement",
]];
- if (self.debugLoggingEnabled)
+ if (self.currentState.debugLoggingEnabled)
{
[settingsTitles addObjectsFromArray:@[
@"Print Telemetry Logfile",
@@ -512,24 +469,25 @@ CLLocationCoordinate2D randomWorldCoordinate() {
[self.mapView resetPosition];
break;
case MBXSettingsDebugToolsTileBoundaries:
- self.mapView.debugMask ^= MGLMapDebugTileBoundariesMask;
+ self.currentState.debugMask ^= MGLMapDebugTileBoundariesMask;
break;
case MBXSettingsDebugToolsTileInfo:
- self.mapView.debugMask ^= MGLMapDebugTileInfoMask;
+ self.currentState.debugMask ^= MGLMapDebugTileInfoMask;
break;
case MBXSettingsDebugToolsTimestamps:
- self.mapView.debugMask ^= MGLMapDebugTimestampsMask;
+ self.currentState.debugMask ^= MGLMapDebugTimestampsMask;
break;
case MBXSettingsDebugToolsCollisionBoxes:
- self.mapView.debugMask ^= MGLMapDebugCollisionBoxesMask;
+ self.currentState.debugMask ^= MGLMapDebugCollisionBoxesMask;
break;
case MBXSettingsDebugToolsOverdrawVisualization:
- self.mapView.debugMask ^= MGLMapDebugOverdrawVisualizationMask;
+ self.currentState.debugMask ^= MGLMapDebugOverdrawVisualizationMask;
break;
case MBXSettingsDebugToolsShowZoomLevel:
{
- self.mapInfoHUDEnabled = !self.mapInfoHUDEnabled;
- self.hudLabel.hidden = !self.mapInfoHUDEnabled;
+ self.zoomLevelOrnamentEnabled = !self.zoomLevelOrnamentEnabled;
+ self.currentState.showsZoomLevelOrnament = self.zoomLevelOrnamentEnabled;
+ self.hudLabel.hidden = !self.zoomLevelOrnamentEnabled;
self.reuseQueueStatsEnabled = NO;
[self updateHUD];
break;
@@ -537,14 +495,16 @@ CLLocationCoordinate2D randomWorldCoordinate() {
case MBXSettingsDebugToolsShowFrameTimeGraph:
{
self.frameTimeGraphEnabled = !self.frameTimeGraphEnabled;
+ self.currentState.showsTimeFrameGraph = !self.currentState.showsTimeFrameGraph;
self.frameTimeGraphView.hidden = !self.frameTimeGraphEnabled;
+ [self updateHUD];
break;
}
case MBXSettingsDebugToolsShowReuseQueueStats:
{
- self.reuseQueueStatsEnabled = !self.reuseQueueStatsEnabled;
- self.hudLabel.hidden = !self.reuseQueueStatsEnabled;
- self.mapInfoHUDEnabled = NO;
+ self.reuseQueueStatsEnabled = !self.currentState.reuseQueueStatsEnabled;
+ self.hudLabel.hidden = !self.currentState.reuseQueueStatsEnabled;
+ self.zoomLevelOrnamentEnabled = NO;
[self updateHUD];
break;
}
@@ -552,6 +512,9 @@ CLLocationCoordinate2D randomWorldCoordinate() {
NSAssert(NO, @"All debug tools setting rows should be implemented");
break;
}
+
+ self.mapView.debugMask = self.currentState.debugMask;
+
break;
case MBXSettingsAnnotations:
switch (indexPath.row)
@@ -2345,9 +2308,10 @@ CLLocationCoordinate2D randomWorldCoordinate() {
}
- (void)updateHUD {
- if (!self.reuseQueueStatsEnabled && !self.mapInfoHUDEnabled) return;
- if (self.hudLabel.hidden) self.hudLabel.hidden = NO;
+ if (self.reuseQueueStatsEnabled == NO && self.zoomLevelOrnamentEnabled == NO) {
+ return;
+ }
NSString *hudString;
@@ -2357,7 +2321,7 @@ CLLocationCoordinate2D randomWorldCoordinate() {
queuedAnnotations += queue.count;
}
hudString = [NSString stringWithFormat:@"Visible: %ld Queued: %ld", (unsigned long)self.mapView.visibleAnnotations.count, (unsigned long)queuedAnnotations];
- } else if (self.mapInfoHUDEnabled) {
+ } else if (self.zoomLevelOrnamentEnabled) {
hudString = [NSString stringWithFormat:@"%.f FPS (%.1fms) ∕ %.2f ∕ ↕\U0000FE0E%.f° ∕ %.f°",
roundf(self.mapView.averageFrameRate), self.mapView.averageFrameTime,
self.mapView.zoomLevel, self.mapView.camera.pitch, self.mapView.direction];
@@ -2420,4 +2384,39 @@ CLLocationCoordinate2D randomWorldCoordinate() {
}
}
+- (void)saveCurrentMapState:(__unused NSNotification *)notification {
+
+ // The following properties can change after the view loads so we need to save their
+ // state before exiting the view controller.
+ self.currentState.camera = self.mapView.camera;
+ self.currentState.showsUserLocation = self.mapView.showsUserLocation;
+ self.currentState.userTrackingMode = self.mapView.userTrackingMode;
+ self.currentState.showsUserHeadingIndicator = self.mapView.showsUserHeadingIndicator;
+ self.currentState.showsMapScale = self.mapView.showsScale;
+ self.currentState.showsZoomLevelOrnament = self.zoomLevelOrnamentEnabled;
+ self.currentState.showsTimeFrameGraph = self.frameTimeGraphEnabled;
+ self.currentState.debugMask = self.mapView.debugMask;
+ self.currentState.debugLoggingEnabled = self.debugLoggingEnabled;
+ self.currentState.reuseQueueStatsEnabled = self.reuseQueueStatsEnabled;
+
+ [[MBXStateManager sharedManager] saveState:self.currentState];
+}
+
+- (void)restoreMapState:(__unused NSNotification *)notification {
+ MBXState *currentState = [MBXStateManager sharedManager].currentState;
+
+ self.mapView.camera = currentState.camera;
+ self.mapView.showsUserLocation = currentState.showsUserLocation;
+ self.mapView.userTrackingMode = currentState.userTrackingMode;
+ self.mapView.showsUserHeadingIndicator = currentState.showsUserHeadingIndicator;
+ self.mapView.showsScale = currentState.showsMapScale;
+ self.zoomLevelOrnamentEnabled = currentState.showsZoomLevelOrnament;
+ self.frameTimeGraphEnabled = currentState.showsTimeFrameGraph;
+ self.mapView.debugMask = currentState.debugMask;
+ self.debugLoggingEnabled = currentState.debugLoggingEnabled;
+ self.reuseQueueStatsEnabled = currentState.reuseQueueStatsEnabled;
+
+ self.currentState = currentState;
+}
+
@end
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index cbeeebd7bc..8cb261c64b 100644
--- a/platform/ios/ios.xcodeproj/project.pbxproj
+++ b/platform/ios/ios.xcodeproj/project.pbxproj
@@ -14,6 +14,8 @@
071BBB071EE77631001FB02A /* MGLImageSourceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 071BBB051EE7761A001FB02A /* MGLImageSourceTests.m */; };
074A7F0D2277C093001A62D1 /* insert_access_token.sh in Resources */ = {isa = PBXBuildFile; fileRef = 074A7F0C2277C093001A62D1 /* insert_access_token.sh */; };
074A7F0E2277C093001A62D1 /* insert_access_token.sh in Resources */ = {isa = PBXBuildFile; fileRef = 074A7F0C2277C093001A62D1 /* insert_access_token.sh */; };
+ 075AF842227B6762008D7A4C /* MBXState.m in Sources */ = {isa = PBXBuildFile; fileRef = 075AF841227B6762008D7A4C /* MBXState.m */; };
+ 075AF845227B67C6008D7A4C /* MBXStateManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 075AF844227B67C6008D7A4C /* MBXStateManager.m */; };
076171C32139C70900668A35 /* MGLMapViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 076171C22139C70900668A35 /* MGLMapViewTests.m */; };
076171C72141A91700668A35 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 076171C62141A91700668A35 /* Settings.bundle */; };
077061DA215DA00E000FEF62 /* MGLTestLocationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 077061D9215DA00E000FEF62 /* MGLTestLocationManager.m */; };
@@ -854,6 +856,10 @@
071BBAFD1EE75CD4001FB02A /* MGLImageSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLImageSource.mm; sourceTree = "<group>"; };
071BBB051EE7761A001FB02A /* MGLImageSourceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLImageSourceTests.m; path = ../../darwin/test/MGLImageSourceTests.m; sourceTree = "<group>"; };
074A7F0C2277C093001A62D1 /* insert_access_token.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = insert_access_token.sh; sourceTree = "<group>"; };
+ 075AF840227B6762008D7A4C /* MBXState.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBXState.h; sourceTree = "<group>"; };
+ 075AF841227B6762008D7A4C /* MBXState.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBXState.m; sourceTree = "<group>"; };
+ 075AF843227B67C5008D7A4C /* MBXStateManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBXStateManager.h; sourceTree = "<group>"; };
+ 075AF844227B67C6008D7A4C /* MBXStateManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBXStateManager.m; sourceTree = "<group>"; };
076171C22139C70900668A35 /* MGLMapViewTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = MGLMapViewTests.m; path = ../../darwin/test/MGLMapViewTests.m; sourceTree = "<group>"; };
076171C62141A91700668A35 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; name = Settings.bundle; path = app/Settings.bundle; sourceTree = SOURCE_ROOT; };
077061D9215DA00E000FEF62 /* MGLTestLocationManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLTestLocationManager.m; sourceTree = "<group>"; };
@@ -1969,6 +1975,10 @@
076171C62141A91700668A35 /* Settings.bundle */,
9604FC341F313A5E003EEA02 /* Fixtures */,
DA1DC94D1CB6C1C2006E619F /* Supporting Files */,
+ 075AF840227B6762008D7A4C /* MBXState.h */,
+ 075AF841227B6762008D7A4C /* MBXState.m */,
+ 075AF843227B67C5008D7A4C /* MBXStateManager.h */,
+ 075AF844227B67C6008D7A4C /* MBXStateManager.m */,
);
name = "Demo App";
path = app;
@@ -3186,7 +3196,9 @@
DA1DC9991CB6E054006E619F /* MBXAppDelegate.m in Sources */,
6FA9341721EF372100AA9CA8 /* MBXOrnamentsViewController.m in Sources */,
DA1DC96B1CB6C6B7006E619F /* MBXOfflinePacksTableViewController.m in Sources */,
+ 075AF845227B67C6008D7A4C /* MBXStateManager.m in Sources */,
DA1DC96A1CB6C6B7006E619F /* MBXCustomCalloutView.m in Sources */,
+ 075AF842227B6762008D7A4C /* MBXState.m in Sources */,
927FBCFC1F4DAA8300F8BF1F /* MBXSnapshotsViewController.m in Sources */,
DA1DC99B1CB6E064006E619F /* MBXViewController.m in Sources */,
40FDA76B1CCAAA6800442548 /* MBXAnnotationView.m in Sources */,