diff --git a/Sources/MapboxNavigation/CarPlayNavigationViewController.swift b/Sources/MapboxNavigation/CarPlayNavigationViewController.swift index 7aeadea47e4..d9ce11196e9 100644 --- a/Sources/MapboxNavigation/CarPlayNavigationViewController.swift +++ b/Sources/MapboxNavigation/CarPlayNavigationViewController.swift @@ -83,6 +83,8 @@ open class CarPlayNavigationViewController: UIViewController, BuildingHighlighti /** A Boolean value that determines whether the map annotates the intersections on current step during active navigation. + If `true`, the map would display an icon of a traffic control device on the intersection, + such as traffic signal, stop sign, yield sign, or railroad crossing. Defaults to `true`. */ public var annotatesIntersectionsAlongRoute: Bool = true { diff --git a/Sources/MapboxNavigation/NavigationMapView+Annotations.swift b/Sources/MapboxNavigation/NavigationMapView+Annotations.swift index 3137ffed52f..6c071a08441 100644 --- a/Sources/MapboxNavigation/NavigationMapView+Annotations.swift +++ b/Sources/MapboxNavigation/NavigationMapView+Annotations.swift @@ -412,36 +412,19 @@ extension NavigationMapView { func updateIntersectionSymbolImages(styleType: StyleType?) { let style = mapView.mapboxMap.style let styleType = styleType ?? .day + let iconNameToIdentifier: [String: String] = ["trafficSignal": ImageIdentifier.trafficSignal, + "railroadCrossing": ImageIdentifier.railroadCrossing, + "yieldSign": ImageIdentifier.yieldSign, + "stopSign": ImageIdentifier.stopSign] do { - if styleType == .day { - if let trafficSignlaDay = Bundle.mapboxNavigation.image(named: "TrafficSignalDay") { - try style.addImage(trafficSignlaDay, id: ImageIdentifier.trafficSignal) - } - if let railroadCrossingDay = Bundle.mapboxNavigation.image(named: "RailroadCrossingDay") { - try style.addImage(railroadCrossingDay, id: ImageIdentifier.railroadCrossing) - } - if let yieldSignDay = Bundle.mapboxNavigation.image(named: "YieldSignDay") { - try style.addImage(yieldSignDay, id: ImageIdentifier.yieldSign) - } - if let stopSignDay = Bundle.mapboxNavigation.image(named: "StopSignDay") { - try style.addImage(stopSignDay, id: ImageIdentifier.stopSign) - } - } else { - if let trafficSignalNight = Bundle.mapboxNavigation.image(named: "TrafficSignalNight") { - try style.addImage(trafficSignalNight, id: ImageIdentifier.trafficSignal) - } - if let railroadCrossingNight = Bundle.mapboxNavigation.image(named: "RailroadCrossingNight") { - try style.addImage(railroadCrossingNight, id: ImageIdentifier.railroadCrossing) - } - if let yieldSignNight = Bundle.mapboxNavigation.image(named: "YieldSignNight") { - try style.addImage(yieldSignNight, id: ImageIdentifier.yieldSign) - } - if let stopSignNight = Bundle.mapboxNavigation.image(named: "StopSignNight") { - try style.addImage(stopSignNight, id: ImageIdentifier.stopSign) + for iconType in iconNameToIdentifier.keys { + let iconName = iconType.firstCapitalized + styleType.description.firstCapitalized + if let imageIdentifier = iconNameToIdentifier[iconType], + let iconImage = Bundle.mapboxNavigation.image(named: iconName) { + try style.addImage(iconImage, id: imageIdentifier) } } - } catch { Log.error("Error occured while updating intersection signal images: \(error.localizedDescription).", category: .navigationUI) diff --git a/Sources/MapboxNavigation/NavigationViewController.swift b/Sources/MapboxNavigation/NavigationViewController.swift index 6a04447c037..0deb78a66ac 100644 --- a/Sources/MapboxNavigation/NavigationViewController.swift +++ b/Sources/MapboxNavigation/NavigationViewController.swift @@ -118,6 +118,8 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter /** A Boolean value that determines whether the map annotates the intersections on current step during active navigation. + If `true`, the map would display an icon of a traffic control device on the intersection, + such as traffic signal, stop sign, yield sign, or railroad crossing. Defaults to `true`. */ public var annotatesIntersectionsAlongRoute: Bool { diff --git a/Sources/MapboxNavigation/String.swift b/Sources/MapboxNavigation/String.swift index 09d778609bb..d1cd82e3feb 100644 --- a/Sources/MapboxNavigation/String.swift +++ b/Sources/MapboxNavigation/String.swift @@ -27,6 +27,10 @@ extension String { return replacements.reduce(self) { $0.replacingOccurrences(of: $1.of, with: $1.with) } } + var firstCapitalized: String { + return prefix(1).uppercased() + dropFirst() + } + /** Returns the MD5 hash of the string. */