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

Commit

Permalink
[ios] Display map on connected displays
Browse files Browse the repository at this point in the history
Whenever an external display is connected, show a map synchronized with the main map on the main display.
  • Loading branch information
1ec5 committed Jan 10, 2019
1 parent bbb72d2 commit 29683e2
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ @interface MBXViewController () <UITableViewDelegate,
@property (nonatomic) BOOL frameTimeGraphEnabled;
@property (nonatomic) BOOL shouldLimitCameraChanges;
@property (nonatomic) BOOL randomWalk;
@property (nonatomic) NSMutableArray<UIWindow *> *helperWindows;

@end

Expand Down Expand Up @@ -289,6 +290,32 @@ - (void)viewDidLoad
}
}
[self.mapView addGestureRecognizer:singleTap];

// Display a secondary map on any connected external display.
// https://developer.apple.com/documentation/uikit/windows_and_screens/displaying_content_on_a_connected_screen?language=objc
self.helperWindows = [NSMutableArray array];
[[NSNotificationCenter defaultCenter] addObserverForName:UIScreenDidConnectNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
UIScreen *helperScreen = note.object;
UIWindow *helperWindow = [[UIWindow alloc] initWithFrame:helperScreen.bounds];
helperWindow.screen = helperScreen;
UIViewController *helperViewController = [[UIViewController alloc] init];
MGLMapView *helperMapView = [[MGLMapView alloc] initWithFrame:helperWindow.bounds styleURL:MGLStyle.satelliteStreetsStyleURL];
helperMapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
helperMapView.camera = self.mapView.camera;
helperMapView.compassView.hidden = YES;
helperViewController.view = helperMapView;
helperWindow.rootViewController = helperViewController;
helperWindow.hidden = NO;
[self.helperWindows addObject:helperWindow];
}];
[[NSNotificationCenter defaultCenter] addObserverForName:UIScreenDidDisconnectNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
UIScreen *helperScreen = note.object;
for (UIWindow *window in self.helperWindows) {
if (window.screen == helperScreen) {
[self.helperWindows removeObject:window];
}
}
}];
}

- (void)saveState:(__unused NSNotification *)notification
Expand Down Expand Up @@ -2214,6 +2241,7 @@ - (BOOL)mapView:(MGLMapView *)mapView shouldChangeFromCamera:(MGLMapCamera *)old
- (void)mapViewRegionIsChanging:(MGLMapView *)mapView
{
[self updateHUD];
[self updateHelperMapViews];
}

- (void)mapView:(MGLMapView *)mapView regionDidChangeWithReason:(MGLCameraChangeReason)reason animated:(BOOL)animated
Expand All @@ -2223,12 +2251,20 @@ - (void)mapView:(MGLMapView *)mapView regionDidChangeWithReason:(MGLCameraChange
}

[self updateHUD];
[self updateHelperMapViews];
}

- (void)mapView:(MGLMapView *)mapView didUpdateUserLocation:(MGLUserLocation *)userLocation {
[self updateHUD];
}

- (void)updateHelperMapViews {
for (UIWindow *window in self.helperWindows) {
MGLMapView *mapView = (MGLMapView *)window.rootViewController.view;
mapView.camera = self.mapView.camera;
}
}

- (void)updateHUD {
if (!self.reuseQueueStatsEnabled && !self.mapInfoHUDEnabled) return;

Expand Down

0 comments on commit 29683e2

Please sign in to comment.