Skip to content

Commit 0dfa87b

Browse files
committed
Update docs and simplify code.
1 parent bd36da5 commit 0dfa87b

File tree

4 files changed

+17
-26
lines changed

4 files changed

+17
-26
lines changed

Sources/MapboxNavigation/CarPlayNavigationViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ open class CarPlayNavigationViewController: UIViewController, BuildingHighlighti
8383
/**
8484
A Boolean value that determines whether the map annotates the intersections on current step during active navigation.
8585

86+
If `true`, the map would display an icon of a traffic control device on the intersection,
87+
such as traffic signal, stop sign, yield sign, or railroad crossing.
8688
Defaults to `true`.
8789
*/
8890
public var annotatesIntersectionsAlongRoute: Bool = true {

Sources/MapboxNavigation/NavigationMapView+Annotations.swift

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -412,36 +412,19 @@ extension NavigationMapView {
412412
func updateIntersectionSymbolImages(styleType: StyleType?) {
413413
let style = mapView.mapboxMap.style
414414
let styleType = styleType ?? .day
415+
let iconNameToIdentifier: [String: String] = ["trafficSignal": ImageIdentifier.trafficSignal,
416+
"railroadCrossing": ImageIdentifier.railroadCrossing,
417+
"yieldSign": ImageIdentifier.yieldSign,
418+
"stopSign": ImageIdentifier.stopSign]
415419

416420
do {
417-
if styleType == .day {
418-
if let trafficSignlaDay = Bundle.mapboxNavigation.image(named: "TrafficSignalDay") {
419-
try style.addImage(trafficSignlaDay, id: ImageIdentifier.trafficSignal)
420-
}
421-
if let railroadCrossingDay = Bundle.mapboxNavigation.image(named: "RailroadCrossingDay") {
422-
try style.addImage(railroadCrossingDay, id: ImageIdentifier.railroadCrossing)
423-
}
424-
if let yieldSignDay = Bundle.mapboxNavigation.image(named: "YieldSignDay") {
425-
try style.addImage(yieldSignDay, id: ImageIdentifier.yieldSign)
426-
}
427-
if let stopSignDay = Bundle.mapboxNavigation.image(named: "StopSignDay") {
428-
try style.addImage(stopSignDay, id: ImageIdentifier.stopSign)
429-
}
430-
} else {
431-
if let trafficSignalNight = Bundle.mapboxNavigation.image(named: "TrafficSignalNight") {
432-
try style.addImage(trafficSignalNight, id: ImageIdentifier.trafficSignal)
433-
}
434-
if let railroadCrossingNight = Bundle.mapboxNavigation.image(named: "RailroadCrossingNight") {
435-
try style.addImage(railroadCrossingNight, id: ImageIdentifier.railroadCrossing)
436-
}
437-
if let yieldSignNight = Bundle.mapboxNavigation.image(named: "YieldSignNight") {
438-
try style.addImage(yieldSignNight, id: ImageIdentifier.yieldSign)
439-
}
440-
if let stopSignNight = Bundle.mapboxNavigation.image(named: "StopSignNight") {
441-
try style.addImage(stopSignNight, id: ImageIdentifier.stopSign)
421+
for iconType in iconNameToIdentifier.keys {
422+
let iconName = iconType.firstCapitalized + styleType.description.firstCapitalized
423+
if let imageIdentifier = iconNameToIdentifier[iconType],
424+
let iconImage = Bundle.mapboxNavigation.image(named: iconName) {
425+
try style.addImage(iconImage, id: imageIdentifier)
442426
}
443427
}
444-
445428
} catch {
446429
Log.error("Error occured while updating intersection signal images: \(error.localizedDescription).",
447430
category: .navigationUI)

Sources/MapboxNavigation/NavigationViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter
118118
/**
119119
A Boolean value that determines whether the map annotates the intersections on current step during active navigation.
120120

121+
If `true`, the map would display an icon of a traffic control device on the intersection,
122+
such as traffic signal, stop sign, yield sign, or railroad crossing.
121123
Defaults to `true`.
122124
*/
123125
public var annotatesIntersectionsAlongRoute: Bool {

Sources/MapboxNavigation/String.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ extension String {
2727
return replacements.reduce(self) { $0.replacingOccurrences(of: $1.of, with: $1.with) }
2828
}
2929

30+
var firstCapitalized: String {
31+
return prefix(1).uppercased() + dropFirst()
32+
}
33+
3034
/**
3135
Returns the MD5 hash of the string.
3236
*/

0 commit comments

Comments
 (0)