diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a0c41c15ec..96324fcb5e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### Other changes * Added filling jartic traffic codes info reported `Incident`s while navigating. ([#4524](https://github.com/mapbox/mapbox-navigation-ios/pull/4524)) +* Fixed initial pan gesture in CarPlay. ([#4534](https://github.com/mapbox/mapbox-navigation-ios/pull/4534)) ## v2.15.0 diff --git a/Sources/MapboxNavigation/CarPlayManager.swift b/Sources/MapboxNavigation/CarPlayManager.swift index 90f7454b1fa..2b3dac94e35 100644 --- a/Sources/MapboxNavigation/CarPlayManager.swift +++ b/Sources/MapboxNavigation/CarPlayManager.swift @@ -980,18 +980,16 @@ extension CarPlayManager: CPMapTemplateDelegate { private func updatePan(by offset: CGPoint, mapTemplate: CPMapTemplate) { guard let navigationMapView = activeNavigationMapView else { return } - - var cameraState = navigationMapView.mapView.mapboxMap.cameraState - cameraState.center = coordinate(of: offset, in: navigationMapView) - navigationMapView.mapView.mapboxMap.setCamera(to: CameraOptions(cameraState: cameraState)) + + navigationMapView.mapView.mapboxMap.setCamera(to: dragCameraOptions(with: offset, in: navigationMapView)) } - func coordinate(of offset: CGPoint, in navigationMapView: NavigationMapView) -> CLLocationCoordinate2D { + private func dragCameraOptions(with offset: CGPoint, in navigationMapView: NavigationMapView) -> CameraOptions { let contentFrame = navigationMapView.bounds.inset(by: navigationMapView.mapView.safeAreaInsets) let centerPoint = CGPoint(x: contentFrame.midX, y: contentFrame.midY) - let endCameraPoint = CGPoint(x: centerPoint.x - offset.x, y: centerPoint.y - offset.y) + let endCameraPoint = CGPoint(x: centerPoint.x + offset.x, y: centerPoint.y + offset.y) - return navigationMapView.mapView.mapboxMap.coordinate(for: endCameraPoint) + return navigationMapView.mapView.mapboxMap.dragCameraOptions(from: centerPoint, to: endCameraPoint) } public func mapTemplate(_ mapTemplate: CPMapTemplate, panWith direction: CPMapTemplate.PanDirection) {