summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2019-01-09 23:25:40 -0800
committerMinh Nguyễn <mxn@1ec5.org>2019-01-14 15:07:43 -0800
commit6ca2f6c97f957855811e279952c2b10aeacf43dd (patch)
treec20fa54f84b061fdfc83f9c7f69fa8b44478679e
parent6960cb13f7d3d6564de90f5a25884003c33a4c4f (diff)
downloadqtlocation-mapboxgl-upstream/az-perf-event.tar.gz
[ios] Display map on connected displaysupstream/az-perf-event
Whenever an external display is connected, show a map synchronized with the main map on the main display.
-rw-r--r--platform/ios/app/MBXViewController.m36
1 files changed, 36 insertions, 0 deletions
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<UIWindow *> *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;