From b6f50def7bd21a4b35c44f845413a5887933eac7 Mon Sep 17 00:00:00 2001 From: Aleksandr Panchenko Date: Wed, 11 Dec 2024 17:44:22 +0200 Subject: [PATCH] use positionPlacementOnMap for carPly #2689 --- .../DashboardCarPlaySceneDelegate.swift | 5 ++-- .../OACarPlayMapDashboardViewController.mm | 5 +++- Sources/CarPlay/OACarPlayMapViewController.mm | 25 +++++++++++++++---- .../Controllers/Map/OAMapInfoController.mm | 10 ++++++-- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Sources/AppHost/CarPlayDelegate/DashboardCarPlaySceneDelegate.swift b/Sources/AppHost/CarPlayDelegate/DashboardCarPlaySceneDelegate.swift index 7d76fa6f0a..c4916e7f52 100644 --- a/Sources/AppHost/CarPlayDelegate/DashboardCarPlaySceneDelegate.swift +++ b/Sources/AppHost/CarPlayDelegate/DashboardCarPlaySceneDelegate.swift @@ -49,7 +49,7 @@ final class DashboardCarPlaySceneDelegate: UIResponder { ? OAApplicationMode.getFirstAvailableNavigation() : settings.carPlayMode.get() settings.setApplicationModePref(carPlayMode, markAsLastUsed: false) - + let isRoutePlanning = OARoutingHelper.sharedInstance().isRoutePlanningMode() let placement = settings.positionPlacementOnMap.get() var y: Double @@ -58,8 +58,7 @@ final class DashboardCarPlaySceneDelegate: UIResponder { } else { y = placement == EOAPositionPlacement.center.rawValue || isRoutePlanning ? 1.0 : 1.5 } - let heightOffset = 1 - (window.frame.height / mapVC.view.frame.height) - mapVC.setViewportForCarPlayScaleX(1.0, y: y - heightOffset) + mapVC.setViewportForCarPlayScaleX(1.0, y: y) } } else { // if the scene becomes active (sceneWillEnterForeground) before setting the root view controller diff --git a/Sources/AppHost/CarPlayDelegate/OACarPlayMapDashboardViewController.mm b/Sources/AppHost/CarPlayDelegate/OACarPlayMapDashboardViewController.mm index 7becbfa740..f9c83e12b7 100644 --- a/Sources/AppHost/CarPlayDelegate/OACarPlayMapDashboardViewController.mm +++ b/Sources/AppHost/CarPlayDelegate/OACarPlayMapDashboardViewController.mm @@ -8,6 +8,8 @@ #import "OAMapPanelViewController.h" #import "OAMapRendererView.h" #import "OARootViewController.h" +#import "OAMapHudViewController.h" +#import "OAMapInfoController.h" @interface OACarPlayMapDashboardViewController () @@ -34,7 +36,7 @@ - (void)attachMapToWindow [_mapVc.mapView suspendRendering]; [_mapVc removeFromParentViewController]; [_mapVc.view removeFromSuperview]; - + [_mapVc.mapView setTopOffsetOfViewSize:0 bottomOffset:0]; [self addChildViewController:_mapVc]; [self.view addSubview:_mapVc.view]; _mapVc.view.frame = self.view.frame; @@ -60,6 +62,7 @@ - (void)detachFromCarPlayWindow _mapVc.view.frame = mapPanel.view.frame; _mapVc.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [_mapVc.mapView resumeRendering]; + [mapPanel.hudViewController.mapInfoController updateLayout]; } } diff --git a/Sources/CarPlay/OACarPlayMapViewController.mm b/Sources/CarPlay/OACarPlayMapViewController.mm index 59e59330d6..ae8203b9eb 100644 --- a/Sources/CarPlay/OACarPlayMapViewController.mm +++ b/Sources/CarPlay/OACarPlayMapViewController.mm @@ -137,17 +137,30 @@ - (void)updateMapCenterPoint UIEdgeInsets insets = _window.safeAreaInsets; - CGFloat w = self.view.frame.size.width; CGFloat h = self.view.frame.size.height; - - CGFloat widthOffset = MAX(insets.right, insets.left) / w; CGFloat heightOffset = insets.top / h; BOOL isLeftSideDriving = [self isLeftSideDriving]; + + BOOL isRoutePlanning = [OARoutingHelper sharedInstance].isRoutePlanningMode; + EOAPositionPlacement placement = (EOAPositionPlacement) [[OAAppSettings sharedManager].positionPlacementOnMap get]; + double y; + if (placement == EOAPositionPlacementAuto) + y = ([[OAAppSettings sharedManager].rotateMap get] == ROTATE_MAP_BEARING && !isRoutePlanning ? 1.5 : 1.0); + else + y = (placement == EOAPositionPlacementCenter || isRoutePlanning ? 1.0 : 1.5); + if (_isInNavigationMode) - [_mapVc setViewportForCarPlayScaleX:isLeftSideDriving ? 1.5 : 0.5 y:kViewportBottomScale]; + { + [_mapVc setViewportForCarPlayScaleX:isLeftSideDriving ? 1.5 : 0.5 y:y + heightOffset]; + } else - [_mapVc setViewportForCarPlayScaleX:isLeftSideDriving ? 1.0 + widthOffset : 1.0 - widthOffset y:1.0 + heightOffset]; + { + CGFloat w = self.view.frame.size.width; + CGFloat widthOffset = MAX(insets.right, insets.left) / w; + + [_mapVc setViewportForCarPlayScaleX:isLeftSideDriving ? 1.0 + widthOffset : 1.0 - widthOffset y:y + heightOffset]; + } } - (void)setupAlarmSpeedometerStackView @@ -219,6 +232,7 @@ - (void) attachMapToWindow [_mapVc.view removeFromSuperview]; _mapVc.isCarPlayActive = YES; + [_mapVc.mapView setTopOffsetOfViewSize:0 bottomOffset:0]; [self addChildViewController:_mapVc]; [self.view addSubview:_mapVc.view]; _mapVc.view.frame = self.view.frame; @@ -245,6 +259,7 @@ - (void) detachFromCarPlayWindow _mapVc.view.frame = mapPanel.view.frame; _mapVc.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [_mapVc.mapView resumeRendering]; + [mapPanel.hudViewController.mapInfoController updateLayout]; OAAppSettings * settings = [OAAppSettings sharedManager]; if (![settings.batterySavingMode get]) [_mapVc.mapView restoreFrameRefreshRate]; diff --git a/Sources/Controllers/Map/OAMapInfoController.mm b/Sources/Controllers/Map/OAMapInfoController.mm index 41ab5287fd..acaac20680 100644 --- a/Sources/Controllers/Map/OAMapInfoController.mm +++ b/Sources/Controllers/Map/OAMapInfoController.mm @@ -530,8 +530,14 @@ - (void) layoutWidgets topOffset += _mapHudViewController.statusBarViewHeightConstraint.constant; if (bottomOffset > 0) bottomOffset += _mapHudViewController.bottomBarViewHeightConstraint.constant; - [mapView setTopOffsetOfViewSize:topOffset bottomOffset:bottomOffset]; - + + OAMapViewController* mapViewController = [OARootViewController instance].mapPanel.mapViewController; + if (!mapViewController.isCarPlayActive && !mapViewController.isCarPlayDashboardActive) + { + // map render in CarPlay shouldn't take into account topOffset and bottomOffset, which are used in the main app for (top/bottom widget, context menu, etc.). For _renderer->setMapTarget" + [mapView setTopOffsetOfViewSize:topOffset bottomOffset:bottomOffset]; + } + if (hasRightWidgets) { CGSize rightSize = [_rightPanelController calculateContentSize];