From 6ca2f6c97f957855811e279952c2b10aeacf43dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Wed, 9 Jan 2019 23:25:40 -0800 Subject: [ios] Display map on connected displays Whenever an external display is connected, show a map synchronized with the main map on the main display. --- platform/ios/app/MBXViewController.m | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 9e6cbf2a8e..b2c6ca26b3 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -205,6 +205,7 @@ CLLocationCoordinate2D randomWorldCoordinate() { @property (nonatomic) BOOL frameTimeGraphEnabled; @property (nonatomic) BOOL shouldLimitCameraChanges; @property (nonatomic) BOOL randomWalk; +@property (nonatomic) NSMutableArray *helperWindows; @end @@ -289,6 +290,32 @@ CLLocationCoordinate2D randomWorldCoordinate() { } } [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 @@ -2214,6 +2241,7 @@ CLLocationCoordinate2D randomWorldCoordinate() { - (void)mapViewRegionIsChanging:(MGLMapView *)mapView { [self updateHUD]; + [self updateHelperMapViews]; } - (void)mapView:(MGLMapView *)mapView regionDidChangeWithReason:(MGLCameraChangeReason)reason animated:(BOOL)animated @@ -2223,12 +2251,20 @@ CLLocationCoordinate2D randomWorldCoordinate() { } [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; -- cgit v1.2.1