Skip to content

Commit

Permalink
Merge pull request #4193 from osmandapp/change_location_position_CarPlay
Browse files Browse the repository at this point in the history
use positionPlacementOnMap for carPly #2689
  • Loading branch information
alex-osm authored Dec 11, 2024
2 parents 307bf8d + b6f50de commit 718d4a4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#import "OAMapPanelViewController.h"
#import "OAMapRendererView.h"
#import "OARootViewController.h"
#import "OAMapHudViewController.h"
#import "OAMapInfoController.h"

@interface OACarPlayMapDashboardViewController ()

Expand All @@ -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;
Expand All @@ -60,6 +62,7 @@ - (void)detachFromCarPlayWindow
_mapVc.view.frame = mapPanel.view.frame;
_mapVc.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[_mapVc.mapView resumeRendering];
[mapPanel.hudViewController.mapInfoController updateLayout];
}
}

Expand Down
25 changes: 20 additions & 5 deletions Sources/CarPlay/OACarPlayMapViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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];
Expand Down
10 changes: 8 additions & 2 deletions Sources/Controllers/Map/OAMapInfoController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 718d4a4

Please sign in to comment.