Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Debug mask #3742

Merged
merged 2 commits into from
Jan 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions include/mbgl/ios/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ typedef NS_ENUM(NSUInteger, MGLAnnotationVerticalAlignment) {
MGLAnnotationVerticalAlignmentBottom,
};

/** Options for enabling debugging features in an MGLMapView instance. */
typedef NS_OPTIONS(NSUInteger, MGLMapDebugMaskOptions) {
/** Edges of tile boundaries are shown as thick, red lines to help diagnose
tile clipping issues. */
MGLMapDebugTileBoundariesMask = 1 << 1,
/** Each tile shows its tile coordinate (x/y/z) in the upper-left corner. */
MGLMapDebugTileInfoMask = 1 << 2,
/** Each tile shows a timestamp indicating when it was loaded. */
MGLMapDebugTimestampsMask = 1 << 3,
/** Edges of glyphs and symbols are shown as faint, green lines to help
diagnose collision and label placement issues. */
MGLMapDebugCollisionBoxesMask = 1 << 4,
};

/**
An interactive, customizable map view with an interface similar to the one
provided by Apple's MapKit.
Expand Down Expand Up @@ -930,23 +944,19 @@ IB_DESIGNABLE
*/
- (void)removeOverlays:(NS_ARRAY_OF(id <MGLOverlay>) *)overlays;

#pragma mark Debugging
#pragma mark Debugging the Map

/**
A Boolean value that determines whether map debugging information is shown.

The default value of this property is `NO`.
*/
@property (nonatomic, getter=isDebugActive) BOOL debugActive;

/**
Cycle through the options that determine which debugging aids are shown on the
map.
The options that determine which debugging aids are shown on the map.

These options are all disabled by default and should remain disabled in
released software.
released software for performance and aesthetic reasons.
*/
- (void)cycleDebugOptions;
@property (nonatomic) MGLMapDebugMaskOptions debugMask;

@property (nonatomic, getter=isDebugActive) BOOL debugActive __attribute__((deprecated("Use -debugMask and -setDebugMask:.")));

- (void)toggleDebug __attribute__((deprecated("Use -setDebugMask:.")));

/**
Empties the in-memory tile cache.
Expand Down
60 changes: 45 additions & 15 deletions ios/app/MBXViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ - (void)saveState:(__unused NSNotification *)notification
[defaults setObject:archivedCamera forKey:@"MBXCamera"];
[defaults setInteger:self.mapView.userTrackingMode forKey:@"MBXUserTrackingMode"];
[defaults setBool:self.mapView.showsUserLocation forKey:@"MBXShowsUserLocation"];
[defaults setBool:self.mapView.debugActive forKey:@"MBXDebug"];
[defaults setInteger:self.mapView.debugMask forKey:@"MBXDebugMask"];
[defaults synchronize];
}
}
Expand All @@ -127,7 +127,11 @@ - (void)restoreState:(__unused NSNotification *)notification
self.mapView.userTrackingMode = (MGLUserTrackingMode)uncheckedTrackingMode;
}
self.mapView.showsUserLocation = [defaults boolForKey:@"MBXShowsUserLocation"];
self.mapView.debugActive = [defaults boolForKey:@"MBXDebug"];
NSInteger uncheckedDebugMask = [defaults integerForKey:@"MBXDebugMask"];
if (uncheckedDebugMask >= 0)
{
self.mapView.debugMask = (MGLMapDebugMaskOptions)uncheckedDebugMask;
}
}
}

Expand All @@ -140,12 +144,24 @@ - (NSUInteger)supportedInterfaceOrientations

- (void)showSettings
{
MGLMapDebugMaskOptions debugMask = self.mapView.debugMask;
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Map Settings"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Reset Position",
@"Cycle Debug Options",
((debugMask & MGLMapDebugTileBoundariesMask)
? @"Hide Tile Boundaries"
: @"Show Tile Boundaries"),
((debugMask & MGLMapDebugTileInfoMask)
? @"Hide Tile Info"
: @"Show Tile Info"),
((debugMask & MGLMapDebugTimestampsMask)
? @"Hide Tile Timestamps"
: @"Show Tile Timestamps"),
((debugMask & MGLMapDebugCollisionBoxesMask)
? @"Hide Collision Boxes"
: @"Show Collision Boxes"),
@"Empty Memory",
@"Add 100 Points",
@"Add 1,000 Points",
Expand All @@ -154,7 +170,9 @@ - (void)showSettings
@"Start World Tour",
@"Add Custom Callout Point",
@"Remove Annotations",
@"Toggle Custom Style Layer",
(_isShowingCustomStyleLayer
? @"Hide Custom Style Layer"
: @"Show Custom Style Layer"),
@"Print Telemetry Logfile",
@"Delete Telemetry Logfile",
nil];
Expand All @@ -170,25 +188,37 @@ - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSIn
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 1)
{
[self.mapView cycleDebugOptions];
self.mapView.debugMask ^= MGLMapDebugTileBoundariesMask;
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 2)
{
[self.mapView emptyMemoryCache];
self.mapView.debugMask ^= MGLMapDebugTileInfoMask;
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 3)
{
[self parseFeaturesAddingCount:100];
self.mapView.debugMask ^= MGLMapDebugTimestampsMask;
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 4)
{
[self parseFeaturesAddingCount:1000];
self.mapView.debugMask ^= MGLMapDebugCollisionBoxesMask;
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 5)
{
[self parseFeaturesAddingCount:10000];
[self.mapView emptyMemoryCache];
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 6)
{
[self parseFeaturesAddingCount:100];
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 7)
{
[self parseFeaturesAddingCount:1000];
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 8)
{
[self parseFeaturesAddingCount:10000];
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 9)
{
// PNW triangle
//
Expand Down Expand Up @@ -255,19 +285,19 @@ - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSIn
free(polygonCoordinates);
}
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 7)
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 10)
{
[self startWorldTour:actionSheet];
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 8)
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 11)
{
[self presentAnnotationWithCustomCallout];
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 9)
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 12)
{
[self.mapView removeAnnotations:self.mapView.annotations];
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 10)
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 13)
{
if (_isShowingCustomStyleLayer)
{
Expand All @@ -278,12 +308,12 @@ - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSIn
[self insertCustomStyleLayer];
}
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 11)
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 14)
{
NSString *fileContents = [NSString stringWithContentsOfFile:[self telemetryDebugLogfilePath] encoding:NSUTF8StringEncoding error:nil];
NSLog(@"%@", fileContents);
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 12)
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 15)
{
NSString *filePath = [self telemetryDebugLogfilePath];
if ([[NSFileManager defaultManager] isDeletableFileAtPath:filePath]) {
Expand Down
1 change: 0 additions & 1 deletion ios/benchmark/MBXBenchViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ - (void)viewDidLoad
self.mapView.scrollEnabled = NO;
self.mapView.rotateEnabled = NO;
self.mapView.userInteractionEnabled = YES;
[self.mapView setDebugActive:NO];

[self startBenchmarkIteration];

Expand Down
67 changes: 55 additions & 12 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ @implementation MGLMapView

#pragma mark - Setup & Teardown -

@dynamic debugActive;
mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
return std::chrono::duration_cast<mbgl::Duration>(std::chrono::duration<NSTimeInterval>(duration));
Expand Down Expand Up @@ -967,7 +966,7 @@ - (void)sleepGL:(__unused NSNotification *)notification
self.glSnapshotView.image = self.glView.snapshot;
self.glSnapshotView.hidden = NO;

if (_mbglMap->getDebug() != mbgl::MapDebugOptions::NoDebug && [self.glSnapshotView.subviews count] == 0)
if (self.debugMask && [self.glSnapshotView.subviews count] == 0)
{
UIView *snapshotTint = [[UIView alloc] initWithFrame:self.glSnapshotView.bounds];
snapshotTint.autoresizingMask = self.glSnapshotView.autoresizingMask;
Expand Down Expand Up @@ -1641,17 +1640,66 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
return [NSSet setWithObject:@"allowsTilting"];
}

- (MGLMapDebugMaskOptions)debugMask
{
mbgl::MapDebugOptions options = _mbglMap->getDebug();
MGLMapDebugMaskOptions mask = 0;
if (options & mbgl::MapDebugOptions::TileBorders)
{
mask |= MGLMapDebugTileBoundariesMask;
}
if (options & mbgl::MapDebugOptions::ParseStatus)
{
mask |= MGLMapDebugTileInfoMask;
}
if (options & mbgl::MapDebugOptions::Timestamps)
{
mask |= MGLMapDebugTimestampsMask;
}
if (options & mbgl::MapDebugOptions::Collision)
{
mask |= MGLMapDebugCollisionBoxesMask;
}
return mask;
}

- (void)setDebugMask:(MGLMapDebugMaskOptions)debugMask
{
mbgl::MapDebugOptions options = mbgl::MapDebugOptions::NoDebug;
if (debugMask & MGLMapDebugTileBoundariesMask)
{
options |= mbgl::MapDebugOptions::TileBorders;
}
if (debugMask & MGLMapDebugTileInfoMask)
{
options |= mbgl::MapDebugOptions::ParseStatus;
}
if (debugMask & MGLMapDebugTimestampsMask)
{
options |= mbgl::MapDebugOptions::Timestamps;
}
if (debugMask & MGLMapDebugCollisionBoxesMask)
{
options |= mbgl::MapDebugOptions::Collision;
}
_mbglMap->setDebug(options);
}

- (void)setDebugActive:(BOOL)debugActive
{
_mbglMap->setDebug(debugActive ? mbgl::MapDebugOptions::TileBorders
| mbgl::MapDebugOptions::ParseStatus
| mbgl::MapDebugOptions::Collision
: mbgl::MapDebugOptions::NoDebug);
self.debugMask = debugActive ? (MGLMapDebugTileBoundariesMask |
MGLMapDebugTileInfoMask |
MGLMapDebugCollisionBoxesMask) : 0;
}

- (BOOL)isDebugActive
{
return (_mbglMap->getDebug() != mbgl::MapDebugOptions::NoDebug);
return self.debugMask;
}

- (void)toggleDebug
{
self.debugActive = !self.debugActive;
}

- (void)resetNorth
Expand All @@ -1671,11 +1719,6 @@ - (void)resetPosition
self.camera = camera;
}

- (void)cycleDebugOptions
{
_mbglMap->cycleDebugOptions();
}

- (void)emptyMemoryCache
{
_mbglMap->onLowMemory();
Expand Down