From 062bbe3ff5ac02186127f1148c17a5216ef07eb9 Mon Sep 17 00:00:00 2001 From: Jill Cardamon Date: Tue, 6 Sep 2022 11:05:39 -0400 Subject: [PATCH 1/3] Initial fix. --- .../NavigationService.swift | 19 +++++++++++++++++++ .../NavigationViewController.swift | 12 ++++++++++++ .../NavigationViewportDataSource.swift | 1 + 3 files changed, 32 insertions(+) diff --git a/Sources/MapboxCoreNavigation/NavigationService.swift b/Sources/MapboxCoreNavigation/NavigationService.swift index 51abd1d486c..e698532f883 100644 --- a/Sources/MapboxCoreNavigation/NavigationService.swift +++ b/Sources/MapboxCoreNavigation/NavigationService.swift @@ -611,9 +611,28 @@ extension MapboxNavigationService: CLLocationManagerDelegate { // MARK: Handling LocationManager Output public func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) { + // Check if device orientation has changed and inform the location provider accordingly. + updateHeadingForCurrentDeviceOrientation() + print("!!! device orientation: \(UIDevice.current.orientation)") + updateHeadingForCurrentDeviceOrientation() router.locationManager?(manager, didUpdateHeading: newHeading) } + public func updateHeadingForCurrentDeviceOrientation() { + var orientation: CLDeviceOrientation + switch UIDevice.current.orientation { + case .landscapeLeft: + orientation = .landscapeRight + case .landscapeRight: + orientation = .landscapeLeft + default: + orientation = .portrait + } + if locationManager.headingOrientation != orientation { + locationManager.headingOrientation = orientation + } + } + public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { //If we're always simulating, make sure this is a simulated update. if simulationMode == .always, manager != simulatedLocationSource { return } diff --git a/Sources/MapboxNavigation/NavigationViewController.swift b/Sources/MapboxNavigation/NavigationViewController.swift index 0deb78a66ac..c4ddcdae444 100644 --- a/Sources/MapboxNavigation/NavigationViewController.swift +++ b/Sources/MapboxNavigation/NavigationViewController.swift @@ -74,6 +74,15 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter navigationMapView.navigationCamera.viewportDataSource = NavigationViewportDataSource(navigationMapView.mapView, viewportDataSourceType: .active) navigationMapView.navigationCamera.follow() + + let viewportDataSource = navigationMapView.navigationCamera.viewportDataSource as? NavigationViewportDataSource + print("!!! orientation: \(navigationService.locationManager.headingOrientation)") +// print("!!! device orientation: \(UIDevice.current.orientation)") +// if navigationService.locationManager.headingOrientation == .landscapeLeft { +// print("!!! landscape left") +// } else if navigationService.locationManager.headingOrientation == .landscapeRight { +// print("!!! landscape right") +// } } // In case if `NavigationMapView` instance was injected - do not set initial camera options. @@ -987,6 +996,9 @@ extension NavigationViewController: NavigationServiceDelegate { let movePuckToCurrentLocation = !(userArrivedAtWaypoint && snapsUserLocationAnnotationToRoute && preventRerouting) if movePuckToCurrentLocation { + if progress.currentLegProgress.currentStep.transportType == .walking && navigationMapView?.mapView.location.options.puckBearingSource == .course { + navigationMapView?.mapView.location.options.puckBearingSource = .heading + } navigationMapView?.moveUserLocation(to: location, animated: true) } diff --git a/Sources/MapboxNavigation/NavigationViewportDataSource.swift b/Sources/MapboxNavigation/NavigationViewportDataSource.swift index f6e72854800..3aa5bf08c80 100644 --- a/Sources/MapboxNavigation/NavigationViewportDataSource.swift +++ b/Sources/MapboxNavigation/NavigationViewportDataSource.swift @@ -125,6 +125,7 @@ public class NavigationViewportDataSource: ViewportDataSource { NotificationCenter.default.post(name: .navigationCameraViewportDidChange, object: self, userInfo: [ NavigationCamera.NotificationUserInfoKey.cameraOptions: cameraOptions ]) + print("!!! device orientation: \(UIDevice.current.orientation)") } // MARK: CameraOptions Methods From f85d77bd2311af1a20a415ad48bbee398dc94ed0 Mon Sep 17 00:00:00 2001 From: Jill Cardamon Date: Mon, 3 Oct 2022 11:22:12 -0400 Subject: [PATCH 2/3] Remove print statements. --- Sources/MapboxCoreNavigation/NavigationService.swift | 2 -- Sources/MapboxNavigation/NavigationViewController.swift | 9 --------- 2 files changed, 11 deletions(-) diff --git a/Sources/MapboxCoreNavigation/NavigationService.swift b/Sources/MapboxCoreNavigation/NavigationService.swift index e698532f883..4d07f85eb9d 100644 --- a/Sources/MapboxCoreNavigation/NavigationService.swift +++ b/Sources/MapboxCoreNavigation/NavigationService.swift @@ -613,8 +613,6 @@ extension MapboxNavigationService: CLLocationManagerDelegate { public func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) { // Check if device orientation has changed and inform the location provider accordingly. updateHeadingForCurrentDeviceOrientation() - print("!!! device orientation: \(UIDevice.current.orientation)") - updateHeadingForCurrentDeviceOrientation() router.locationManager?(manager, didUpdateHeading: newHeading) } diff --git a/Sources/MapboxNavigation/NavigationViewController.swift b/Sources/MapboxNavigation/NavigationViewController.swift index c4ddcdae444..467e5d77085 100644 --- a/Sources/MapboxNavigation/NavigationViewController.swift +++ b/Sources/MapboxNavigation/NavigationViewController.swift @@ -74,15 +74,6 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter navigationMapView.navigationCamera.viewportDataSource = NavigationViewportDataSource(navigationMapView.mapView, viewportDataSourceType: .active) navigationMapView.navigationCamera.follow() - - let viewportDataSource = navigationMapView.navigationCamera.viewportDataSource as? NavigationViewportDataSource - print("!!! orientation: \(navigationService.locationManager.headingOrientation)") -// print("!!! device orientation: \(UIDevice.current.orientation)") -// if navigationService.locationManager.headingOrientation == .landscapeLeft { -// print("!!! landscape left") -// } else if navigationService.locationManager.headingOrientation == .landscapeRight { -// print("!!! landscape right") -// } } // In case if `NavigationMapView` instance was injected - do not set initial camera options. From c85e6331adb1ed4d16d593bdcc5ffb65db620c21 Mon Sep 17 00:00:00 2001 From: Jill Cardamon Date: Thu, 27 Oct 2022 13:47:33 -0400 Subject: [PATCH 3/3] Use dotted line for walking. Need at add image asset. --- .../MapboxNavigation/NavigationMapView.swift | 37 ++++++++++++++++++- .../NavigationMapViewIdentifiers.swift | 1 + 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Sources/MapboxNavigation/NavigationMapView.swift b/Sources/MapboxNavigation/NavigationMapView.swift index ec51a2d7eeb..262bf44e366 100755 --- a/Sources/MapboxNavigation/NavigationMapView.swift +++ b/Sources/MapboxNavigation/NavigationMapView.swift @@ -39,7 +39,7 @@ open class NavigationMapView: UIView { public var showsCongestionForAlternativeRoutes: Bool = false /** - Controls wheter to show restricted portions of a route line. + Controls whether to show restricted portions of a route line. Restricted areas are drawn using `routeRestrictedAreaColor` which is customizable. */ @@ -96,6 +96,11 @@ open class NavigationMapView: UIView { } } + /** + Controls whether to use a dotted line for the route line when the transport type is walking. + */ + public var usesDottedLineForWalking: Bool = true + /** Location manager that is used to track accuracy and status authorization changes. */ @@ -165,6 +170,12 @@ open class NavigationMapView: UIView { } } + var isWalking: Bool { + get { + return routes?.first?.legs.first?.profileIdentifier == .walking ? true : false + } + } + func updateRouteLineWithRouteLineTracksTraversal() { if let routes = self.routes { let offset = fractionTraveled @@ -349,6 +360,15 @@ open class NavigationMapView: UIView { mapView.mapboxMap.style.removeLayers(layerIdentifiers) mapView.mapboxMap.style.removeSources(sourceIdentifiers) + do { + if mapView.mapboxMap.style.image(withId: NavigationMapView.ImageIdentifier.minusImage) != nil { + try mapView.mapboxMap.style.removeImage(withId: NavigationMapView.ImageIdentifier.minusImage) + } + } catch { + Log.error("Failed to remove image \(NavigationMapView.ImageIdentifier.minusImage) from style with error: \(error.localizedDescription).", + category: .navigationUI) + } + routes = nil removeLineGradientStops() } @@ -623,13 +643,22 @@ open class NavigationMapView: UIView { below parentLayerIndentifier: String? = nil, isMainRoute: Bool = true, legIndex: Int? = nil) -> String? { - guard let defaultShape = route.shape else { return nil } + guard let defaultShape = route.shape, + let circleImage = Bundle.mapboxNavigation.image(named: "minus")?.withRenderingMode(.alwaysTemplate) else { return nil } let shape = delegate?.navigationMapView(self, shapeFor: route) ?? defaultShape let geoJSONSource = self.geoJSONSource(shape) let sourceIdentifier = route.identifier(.source(isMainRoute: isMainRoute, isSourceCasing: false)) do { + if isWalking && usesDottedLineForWalking && mapView.mapboxMap.style.image(withId: NavigationMapView.ImageIdentifier.minusImage) == nil { + try mapView.mapboxMap.style.addImage(circleImage, + id: NavigationMapView.ImageIdentifier.minusImage, + sdf: true, + stretchX: [ImageStretches(first: 0, second: 0)], + stretchY: [ImageStretches(first: 0, second: 0)]) + } + if mapView.mapboxMap.style.sourceExists(withId: sourceIdentifier) { try mapView.mapboxMap.style.updateGeoJSONSource(withId: sourceIdentifier, geoJSON: .geometry(.lineString(shape))) @@ -659,6 +688,9 @@ open class NavigationMapView: UIView { lineLayer?.lineWidth = .expression(Expression.routeLineWidthExpression()) lineLayer?.lineJoin = .constant(.round) lineLayer?.lineCap = .constant(.round) + if isWalking && usesDottedLineForWalking { + lineLayer?.linePattern = .constant(.name(NavigationMapView.ImageIdentifier.minusImage)) + } if isMainRoute { let congestionFeatures = route.congestionFeatures(legIndex: legIndex, roadClassesWithOverriddenCongestionLevels: roadClassesWithOverriddenCongestionLevels) @@ -717,6 +749,7 @@ open class NavigationMapView: UIView { @discardableResult func addRouteCasingLayer(_ route: Route, below parentLayerIndentifier: String? = nil, isMainRoute: Bool = true) -> String? { + if isWalking && usesDottedLineForWalking { return nil } guard let defaultShape = route.shape else { return nil } let shape = delegate?.navigationMapView(self, casingShapeFor: route) ?? defaultShape diff --git a/Sources/MapboxNavigation/NavigationMapViewIdentifiers.swift b/Sources/MapboxNavigation/NavigationMapViewIdentifiers.swift index 9c9682dc1ed..374a70ea679 100644 --- a/Sources/MapboxNavigation/NavigationMapViewIdentifiers.swift +++ b/Sources/MapboxNavigation/NavigationMapViewIdentifiers.swift @@ -42,6 +42,7 @@ extension NavigationMapView { static let railroadCrossing = "railroad_crossing" static let yieldSign = "yield_sign" static let stopSign = "stop_sign" + static let minusImage = "minus" } struct ModelKeyIdentifier {