Skip to content

Commit eb941e2

Browse files
committed
Annotate intersections in active navigation session only.
1 parent a9b9487 commit eb941e2

14 files changed

+121
-112
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
* `NavigationMapView.removeAlternativeRoutes()` and `NavigationMapView.removeContinuousAlternativeRoutesDurations()` were made public to provide a way to remove previously shown alternative routes and alternative routes duration annotations, respectively. ([#4134](https://github.com/mapbox/mapbox-navigation-ios/pull/4134))
2222
* Fixed an issue where tapping on a route duration annotation that overlaps a different route would cause the wrong route to be passed into `NavigationMapViewDelegate.navigationMapView(_:didSelect:)` or `NavigationMapViewDelegate.navigationMapView(_:didSelect:)`. ([#4133](https://github.com/mapbox/mapbox-navigation-ios/pull/4133))
23-
* Added `NavigationMapView.showsIntersectionSignals`, `NavigationMapView.showIntersectionSignals(with:)` and `NavigationMapView.removeIntersectionSignals()` to annotate traffic control devices on the current route step during active navigation. ([#4185](https://github.com/mapbox/mapbox-navigation-ios/pull/4185))
23+
* Added `NavigationViewController.annotatesIntersectionsAlongRoute` and `CarPlayNavigationViewController.annotatesIntersectionsAlongRoute` to annotate intersections on the current route step during active navigation. ([#4185](https://github.com/mapbox/mapbox-navigation-ios/pull/4185))
2424

2525
### Routing
2626

Example/AppDelegate+CarPlay.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ extension AppDelegate: CarPlayManagerDelegate {
9292
// Render part of the route that has been traversed with full transparency, to give the illusion of a disappearing route.
9393
navigationViewController.routeLineTracksTraversal = true
9494
navigationViewController.navigationMapView?.showsRestrictedAreasOnRoute = true
95-
navigationViewController.navigationMapView?.showsIntersectionSignals = true
9695

9796
// Example of building highlighting in 3D.
9897
navigationViewController.waypointStyle = .extrudedBuilding

Example/CustomViewController.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class CustomViewController: UIViewController {
6767
// By setting the `NavigationMapView.routeLineTracksTraversal` to `true`, it would allow the main route shown with
6868
// traversed part disappearing effect in a standalone `NavigationMapView` during active navigation.
6969
self.navigationMapView.routeLineTracksTraversal = true
70-
self.navigationMapView.showsIntersectionSignals = true
7170
if self.navigationMapView.mapView.mapboxMap.style.layerExists(withId: "road-intersection") {
7271
// Provide the custom layer position for route line in active navigation.
7372
self.navigationMapView.show([self.navigationService.route], layerPosition: .below("road-intersection") ,legIndex: 0)
@@ -152,9 +151,6 @@ class CustomViewController: UIViewController {
152151
// without redrawing the main route.
153152
navigationMapView.updateRouteLine(routeProgress: routeProgress, coordinate: location.coordinate, shouldRedraw: routeProgress.legIndex != currentLegIndex)
154153
currentLegIndex = routeProgress.legIndex
155-
156-
// Add intersection signals
157-
navigationMapView.showIntersectionSignals(with: routeProgress)
158154
}
159155

160156
@objc func updateInstructionsBanner(notification: NSNotification) {
@@ -177,8 +173,6 @@ class CustomViewController: UIViewController {
177173
navigationMapView.updateRouteLine(routeProgress: navigationService.routeProgress,
178174
coordinate: navigationService.router.location?.coordinate,
179175
shouldRedraw: true)
180-
181-
navigationMapView.showIntersectionSignals(with: navigationService.routeProgress)
182176
}
183177

184178
@objc func refresh(_ notification: NSNotification) {

Example/ViewController.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,6 @@ class ViewController: UIViewController {
666666
self.navigationMapView = nil
667667
self.passiveLocationManager = nil
668668
navigationViewController.navigationMapView?.showsRestrictedAreasOnRoute = true
669-
navigationViewController.navigationMapView?.showsIntersectionSignals = true
670669

671670
// Animate top and bottom banner views presentation.
672671
navigationViewController.navigationView.bottomBannerContainerView.show(duration: 1.0,

Sources/MapboxNavigation/CarPlayMapViewController.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ extension CarPlayMapViewController: StyleManagerDelegate {
403403
public func styleManager(_ styleManager: StyleManager, didApply style: Style) {
404404
let mapboxMapStyle = navigationMapView.mapView.mapboxMap.style
405405
if mapboxMapStyle.uri?.rawValue != style.mapStyleURL.absoluteString {
406-
navigationMapView.styleType = style.styleType
407406
let styleURI = StyleURI(url: style.mapStyleURL)
408407
mapboxMapStyle.uri = styleURI
409408
// Update the sprite repository of wayNameView when map style changes.

Sources/MapboxNavigation/CarPlayNavigationViewController.swift

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ open class CarPlayNavigationViewController: UIViewController, BuildingHighlighti
8080
}
8181
}
8282

83+
/**
84+
A Boolean value that determines whether the map annotates the intersections on current step during active navigation.
85+
86+
Defaults to `true`.
87+
*/
88+
public var annotatesIntersectionsAlongRoute: Bool = true {
89+
didSet {
90+
updateIntersectionsAlongRoute()
91+
}
92+
}
93+
8394
/**
8495
`AlternativeRoute`s user might take during this trip to reach the destination using another road.
8596

@@ -777,10 +788,13 @@ open class CarPlayNavigationViewController: UIViewController, BuildingHighlighti
777788
navigationMapView?.showWaypoints(on: routeProgress.route, legIndex: legIndex)
778789
}
779790

791+
if annotatesIntersectionsAlongRoute {
792+
navigationMapView?.updateIntersectionSignals(with: routeProgress)
793+
}
794+
780795
navigationMapView?.updateRouteLine(routeProgress: routeProgress, coordinate: location.coordinate, shouldRedraw: legIndex != currentLegIndexMapped)
781796
currentLegIndexMapped = legIndex
782797

783-
navigationMapView?.showIntersectionSignals(with: routeProgress)
784798
}
785799

786800
private func checkTunnelState(at location: CLLocation, along progress: RouteProgress) {
@@ -875,7 +889,9 @@ open class CarPlayNavigationViewController: UIViewController, BuildingHighlighti
875889
}
876890
navigationMapView?.showWaypoints(on: progress.route, legIndex: legIndex)
877891

878-
navigationMapView?.showIntersectionSignals(with: progress)
892+
if annotatesIntersectionsAlongRoute {
893+
navigationMapView?.updateIntersectionSignals(with: progress)
894+
}
879895
}
880896

881897
func updateManeuvers(_ routeProgress: RouteProgress) {
@@ -1017,6 +1033,15 @@ open class CarPlayNavigationViewController: UIViewController, BuildingHighlighti
10171033
carInterfaceController.dismissTemplate(animated: true)
10181034
carInterfaceController.presentTemplate(waypointArrival, animated: true)
10191035
}
1036+
1037+
func updateIntersectionsAlongRoute() {
1038+
if annotatesIntersectionsAlongRoute {
1039+
navigationMapView?.updateIntersectionSymbolImages(styleType: styleManager?.currentStyleType)
1040+
navigationMapView?.updateIntersectionSignals(with: navigationService.routeProgress)
1041+
} else {
1042+
navigationMapView?.removeIntersectionSignals()
1043+
}
1044+
}
10201045
}
10211046

10221047
// MARK: StyleManagerDelegate Methods
@@ -1037,7 +1062,6 @@ extension CarPlayNavigationViewController: StyleManagerDelegate {
10371062
public func styleManager(_ styleManager: StyleManager, didApply style: Style) {
10381063
let mapboxMapStyle = navigationMapView?.mapView.mapboxMap.style
10391064
if mapboxMapStyle?.uri?.rawValue != style.mapStyleURL.absoluteString {
1040-
navigationMapView?.styleType = style.styleType
10411065
let styleURI = StyleURI(url: style.mapStyleURL)
10421066
mapboxMapStyle?.uri = styleURI
10431067
// Update the sprite repository of wayNameView when map style changes.
@@ -1046,6 +1070,7 @@ extension CarPlayNavigationViewController: StyleManagerDelegate {
10461070

10471071
updateMapTemplateStyle()
10481072
updateManeuvers(navigationService.routeProgress)
1073+
updateIntersectionsAlongRoute()
10491074
}
10501075

10511076
public func styleManagerDidRefreshAppearance(_ styleManager: StyleManager) {

Sources/MapboxNavigation/NavigationMapView+Annotations.swift

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -398,27 +398,33 @@ extension NavigationMapView {
398398
/**
399399
Updates the image assets in the map style for the route intersection signals.
400400
*/
401-
func updateIntersectionSymbolImages() throws {
401+
func updateIntersectionSymbolImages(styleType: StyleType?) {
402402
let style = mapView.mapboxMap.style
403+
let styleType = styleType ?? .day
403404

404-
if style.image(withId: ImageIdentifier.trafficSignalDay) == nil,
405-
let trafficSignlaDay = Bundle.mapboxNavigation.image(named: "TrafficSignalDay") {
406-
try style.addImage(trafficSignlaDay, id: ImageIdentifier.trafficSignalDay)
407-
}
408-
409-
if style.image(withId: ImageIdentifier.trafficSignalNight) == nil,
410-
let trafficSignalNight = Bundle.mapboxNavigation.image(named: "TrafficSignalNight") {
411-
try style.addImage(trafficSignalNight, id: ImageIdentifier.trafficSignalNight)
412-
}
413-
414-
if style.image(withId: ImageIdentifier.railroadCrossingDay) == nil,
415-
let railroadCrossingDay = Bundle.mapboxNavigation.image(named: "RailroadCrossingDay") {
416-
try style.addImage(railroadCrossingDay, id: ImageIdentifier.railroadCrossingDay)
417-
}
418-
419-
if style.image(withId: ImageIdentifier.railroadCrossingNight) == nil,
420-
let railroadCrossingNight = Bundle.mapboxNavigation.image(named: "RailroadCrossingNight") {
421-
try style.addImage(railroadCrossingNight, id: ImageIdentifier.railroadCrossingNight)
405+
do {
406+
if styleType == .day {
407+
if let trafficSignlaDay = Bundle.mapboxNavigation.image(named: "TrafficSignalDay") {
408+
try style.addImage(trafficSignlaDay, id: ImageIdentifier.trafficSignal)
409+
}
410+
411+
if let railroadCrossingDay = Bundle.mapboxNavigation.image(named: "RailroadCrossingDay") {
412+
try style.addImage(railroadCrossingDay, id: ImageIdentifier.railroadCrossing)
413+
}
414+
415+
} else {
416+
if let trafficSignalNight = Bundle.mapboxNavigation.image(named: "TrafficSignalNight") {
417+
try style.addImage(trafficSignalNight, id: ImageIdentifier.trafficSignal)
418+
}
419+
420+
if let railroadCrossingNight = Bundle.mapboxNavigation.image(named: "RailroadCrossingNight") {
421+
try style.addImage(railroadCrossingNight, id: ImageIdentifier.railroadCrossing)
422+
}
423+
}
424+
425+
} catch {
426+
Log.error("Error occured while updating intersection signal images: \(error.localizedDescription).",
427+
category: .navigationUI)
422428
}
423429
}
424430

@@ -434,7 +440,7 @@ extension NavigationMapView {
434440
let stepIntersections = stepProgress.intersectionsIncludingUpcomingManeuverIntersection
435441

436442
for intersection in stepIntersections?.suffix(from: intersectionIndex) ?? [] {
437-
if let feature = signalFeature(from: intersection, styleType: styleType) {
443+
if let feature = signalFeature(from: intersection) {
438444
featureCollection.features.append(feature)
439445
}
440446
}
@@ -469,14 +475,13 @@ extension NavigationMapView {
469475
}
470476
}
471477

472-
private func signalFeature(from intersection: Intersection, styleType: StyleType) -> Feature? {
478+
private func signalFeature(from intersection: Intersection) -> Feature? {
473479
var properties: JSONObject? = nil
474-
let styleTypeString = (styleType == .day) ? "Day" : "Night"
475480
if intersection.railroadCrossing == true {
476-
properties = ["imageName": .string("RailroadCrossing" + styleTypeString)]
481+
properties = ["imageName": .string(ImageIdentifier.railroadCrossing)]
477482
}
478483
if intersection.trafficSignal == true {
479-
properties = ["imageName": .string("TrafficSignal" + styleTypeString)]
484+
properties = ["imageName": .string(ImageIdentifier.trafficSignal)]
480485
}
481486

482487
guard let properties = properties else { return nil }

Sources/MapboxNavigation/NavigationMapView.swift

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,43 +1125,6 @@ open class NavigationMapView: UIView {
11251125
}
11261126
}
11271127

1128-
/**
1129-
Show the signals on the intersections.
1130-
1131-
- parameter routeProgress: The `RouteProgress` that the intersections will be displayed with.
1132-
*/
1133-
public func showIntersectionSignals(with routeProgress: RouteProgress) {
1134-
guard showsIntersectionSignals else {
1135-
removeIntersectionSignals()
1136-
return
1137-
}
1138-
1139-
do {
1140-
try updateIntersectionSymbolImages()
1141-
} catch {
1142-
Log.error("Error occured while updating intersection signal images: \(error.localizedDescription).",
1143-
category: .navigationUI)
1144-
}
1145-
1146-
updateIntersectionSignals(with: routeProgress)
1147-
}
1148-
1149-
/**
1150-
Shows the intersection signals on current step of current route during active navigation.
1151-
*/
1152-
public var showsIntersectionSignals: Bool = false {
1153-
didSet {
1154-
if !showsIntersectionSignals {
1155-
removeIntersectionSignals()
1156-
}
1157-
}
1158-
}
1159-
1160-
/**
1161-
The style type of `NavigationMapView` during active navigation.
1162-
*/
1163-
var styleType: StyleType = .day
1164-
11651128
let continuousAlternativeDurationAnnotationOffset: LocationDistance = 75
11661129

11671130
/**

Sources/MapboxNavigation/NavigationMapViewIdentifiers.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ extension NavigationMapView {
3838
static let markerImage = "default_marker"
3939
static let routeAnnotationLeftHanded = "RouteInfoAnnotationLeftHanded"
4040
static let routeAnnotationRightHanded = "RouteInfoAnnotationRightHanded"
41-
static let trafficSignalDay = "TrafficSignalDay"
42-
static let trafficSignalNight = "TrafficSignalNight"
43-
static let railroadCrossingDay = "RailroadCrossingDay"
44-
static let railroadCrossingNight = "RailroadCrossingNight"
41+
static let trafficSignal = "traffic_signal"
42+
static let railroadCrossing = "railroad_crossing"
4543
}
4644

4745
struct ModelKeyIdentifier {

Sources/MapboxNavigation/NavigationViewController.swift

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter
9191
}
9292
}
9393

94+
/**
95+
A Boolean value that determines whether the map annotates the intersections on current step during active navigation.
96+
97+
Defaults to `true`.
98+
*/
99+
public var annotatesIntersectionsAlongRoute: Bool {
100+
get {
101+
routeOverlayController?.annotatesIntersections ?? true
102+
}
103+
set {
104+
routeOverlayController?.annotatesIntersections = newValue
105+
updateIntersectionsAlongRoute()
106+
}
107+
}
108+
94109
/**
95110
Toggles displaying alternative routes.
96111

@@ -843,6 +858,15 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter
843858
styleManager.applyStyle(type: .day)
844859
}
845860
}
861+
862+
func updateIntersectionsAlongRoute() {
863+
if annotatesIntersectionsAlongRoute {
864+
navigationMapView?.updateIntersectionSymbolImages(styleType: styleManager?.currentStyleType)
865+
navigationMapView?.updateIntersectionSignals(with: navigationService.routeProgress)
866+
} else {
867+
navigationMapView?.removeIntersectionSignals()
868+
}
869+
}
846870
}
847871

848872
// MARK: - NavigationViewDelegate methods
@@ -1179,14 +1203,14 @@ extension NavigationViewController: StyleManagerDelegate {
11791203

11801204
private func updateMapStyle(_ style: Style) {
11811205
if navigationMapView?.mapView.mapboxMap.style.uri?.rawValue != style.mapStyleURL.absoluteString {
1182-
navigationMapView?.styleType = style.styleType
11831206
let styleURI = StyleURI(url: style.mapStyleURL)
11841207
navigationMapView?.mapView.mapboxMap.style.uri = styleURI
11851208
// Update the sprite repository of wayNameView when map style changes.
11861209
ornamentsController?.updateStyle(styleURI: styleURI)
11871210
}
11881211

11891212
currentStatusBarStyle = style.statusBarStyle ?? .default
1213+
updateIntersectionsAlongRoute()
11901214
setNeedsStatusBarAppearanceUpdate()
11911215
}
11921216

0 commit comments

Comments
 (0)