Skip to content

Commit

Permalink
Update docs and simplify code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanMa1991 committed Oct 26, 2022
1 parent bd36da5 commit 0dfa87b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
35 changes: 9 additions & 26 deletions Sources/MapboxNavigation/NavigationMapView+Annotations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Sources/MapboxNavigation/NavigationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions Sources/MapboxNavigation/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 0dfa87b

Please sign in to comment.