Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed initial pan gesture in CarPlay #4534

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 5 additions & 7 deletions Sources/MapboxNavigation/CarPlayManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down