Skip to content

Commit

Permalink
Fixed initial pan gesture in CarPlay
Browse files Browse the repository at this point in the history
  • Loading branch information
kried committed Aug 21, 2023
1 parent 69acb5c commit fcb64ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
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

0 comments on commit fcb64ac

Please sign in to comment.