Skip to content

Commit 57c8edf

Browse files
committed
Annotate intersections in active navigation session only.
1 parent a8e4e59 commit 57c8edf

13 files changed

+121
-109
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* 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))
2222
* Fixed an issue where the shields in the instruction are using the style from last navigation session with the `NavigationMapView` injection used in the new session. ([#4197](https://github.com/mapbox/mapbox-navigation-ios/pull/4197))
2323
* Fixed an issue where the `NavigationMapView.localizeLabels()` method only localized map labels according to the user’s Preferred Language Order setting if the application also had a localization in the preferred language. ([#4205](https://github.com/mapbox/mapbox-navigation-ios/pull/4205))
24-
* 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))
24+
* 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))
2525

2626
### Banners and guidance instructions
2727

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/CarPlayNavigationViewController.swift

Lines changed: 28 additions & 2 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
@@ -1044,6 +1069,7 @@ extension CarPlayNavigationViewController: StyleManagerDelegate {
10441069
wayNameView?.label.updateStyle(styleURI: styleURI, idiom: .carPlay)
10451070
updateMapTemplateStyle()
10461071
updateManeuvers(navigationService.routeProgress)
1072+
updateIntersectionsAlongRoute()
10471073
}
10481074

10491075
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter
115115
}
116116
}
117117

118+
/**
119+
A Boolean value that determines whether the map annotates the intersections on current step during active navigation.
120+
121+
Defaults to `true`.
122+
*/
123+
public var annotatesIntersectionsAlongRoute: Bool {
124+
get {
125+
routeOverlayController?.annotatesIntersections ?? true
126+
}
127+
set {
128+
routeOverlayController?.annotatesIntersections = newValue
129+
updateIntersectionsAlongRoute()
130+
}
131+
}
132+
118133
/**
119134
Toggles displaying alternative routes.
120135

@@ -867,6 +882,15 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter
867882
styleManager.applyStyle(type: .day)
868883
}
869884
}
885+
886+
func updateIntersectionsAlongRoute() {
887+
if annotatesIntersectionsAlongRoute {
888+
navigationMapView?.updateIntersectionSymbolImages(styleType: styleManager?.currentStyleType)
889+
navigationMapView?.updateIntersectionSignals(with: navigationService.routeProgress)
890+
} else {
891+
navigationMapView?.removeIntersectionSignals()
892+
}
893+
}
870894
}
871895

872896
// MARK: - NavigationViewDelegate methods
@@ -1209,6 +1233,7 @@ extension NavigationViewController: StyleManagerDelegate {
12091233

12101234
ornamentsController?.updateStyle(styleURI: styleURI)
12111235
currentStatusBarStyle = style.statusBarStyle ?? .default
1236+
updateIntersectionsAlongRoute()
12121237
setNeedsStatusBarAppearanceUpdate()
12131238
}
12141239

Sources/MapboxNavigation/RouteLineController.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ extension NavigationMapView {
5555
navigationMapView.showVoiceInstructionsOnMap(route: router.route)
5656
}
5757

58-
navigationMapView.showIntersectionSignals(with: router.routeProgress)
58+
if annotatesIntersections {
59+
navigationMapView.updateIntersectionSignals(with: router.routeProgress)
60+
}
5961
}
6062

6163
func navigationViewDidAppear(_ animated: Bool) {
@@ -91,7 +93,9 @@ extension NavigationMapView {
9193
navigationMapView.showVoiceInstructionsOnMap(route: route)
9294
}
9395

94-
navigationMapView.showIntersectionSignals(with: router.routeProgress)
96+
if annotatesIntersections {
97+
navigationMapView.updateIntersectionSignals(with: router.routeProgress)
98+
}
9599
}
96100

97101
func navigationService(_ service: NavigationService, didUpdate progress: RouteProgress, with location: CLLocation, rawLocation: CLLocation) {
@@ -113,10 +117,12 @@ extension NavigationMapView {
113117
navigationMapView.showVoiceInstructionsOnMap(route: route)
114118
}
115119

120+
if annotatesIntersections {
121+
navigationMapView.updateIntersectionSignals(with: progress)
122+
}
123+
116124
navigationMapView.updateRouteLine(routeProgress: progress, coordinate: location.coordinate, shouldRedraw: currentLegIndexMapped != legIndex)
117125
currentLegIndexMapped = legIndex
118-
119-
navigationMapView.showIntersectionSignals(with: router.routeProgress)
120126
}
121127

122128
private func updateMapOverlays(for routeProgress: RouteProgress) {
@@ -133,6 +139,7 @@ extension NavigationMapView {
133139
// MARK: Annotations Overlay
134140

135141
var annotatesSpokenInstructions = false
142+
var annotatesIntersections: Bool = true
136143

137144
private var currentLegIndexMapped = 0
138145
private var currentStepIndexMapped = 0

0 commit comments

Comments
 (0)