Skip to content

Commit 7f9454e

Browse files
committed
clean code before merge
1 parent c9423be commit 7f9454e

File tree

4 files changed

+17
-34
lines changed

4 files changed

+17
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* Renamed public property `MBCongestionAttribute` to `CongestionAttribute`. ([#2808](https://github.com/mapbox/mapbox-navigation-ios/pull/2808))
2727
* `NavigationViewController.mapView` was renamed to `NavigationViewController.navigationMapView`. ([#2808](https://github.com/mapbox/mapbox-navigation-ios/pull/2808))
2828
* `NavigationMapView.highlightBuildings(at:in3D:)` was renamed to `NavigationMapView.highlightBuildings(at:in3D:completion:)`. ([#2827](https://github.com/mapbox/mapbox-navigation-ios/pull/2827))
29-
* Add ability to show congestion levels with different colors on alternative route lines, after receiving multiple routes in `RouteResponse` if `NavigationMapView.showsAlternativeCongestion` is set to `true`. ([#2887](https://github.com/mapbox/mapbox-navigation-ios/pull/2887))
29+
* Add ability to show congestion levels with different colors on alternative route lines, after receiving multiple routes in `RouteResponse` if `NavigationMapView.showsCongestionForAlternativeRoutes` is set to `true`. ([#2887](https://github.com/mapbox/mapbox-navigation-ios/pull/2887))
3030

3131
### Location tracking
3232

Example/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ViewController: UIViewController {
5858

5959
startButton.isEnabled = true
6060
// Show congestion levels on alternative route lines if there're multiple routes in the response.
61-
navigationMapView.showsAlternativeCongestion = true
61+
navigationMapView.showsCongestionForAlternativeRoutes = true
6262
navigationMapView.show(routes)
6363
navigationMapView.showWaypoints(on: currentRoute)
6464
}

Sources/MapboxNavigation/NavigationMapView+VanishingRouteLine.swift

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -344,32 +344,17 @@ extension NavigationMapView {
344344
Given a congestion level, return its associated color.
345345
*/
346346
func congestionColor(for congestionLevel: String?, isMain: Bool) -> UIColor {
347-
if isMain {
348-
switch congestionLevel {
349-
case "low":
350-
return trafficLowColor
351-
case "moderate":
352-
return trafficModerateColor
353-
case "heavy":
354-
return trafficHeavyColor
355-
case "severe":
356-
return trafficSevereColor
357-
default:
358-
return trafficUnknownColor
359-
}
360-
} else {
361-
switch congestionLevel {
362-
case "low":
363-
return alternativeTrafficLowColor
364-
case "moderate":
365-
return alternativeTrafficModerateColor
366-
case "heavy":
367-
return alternativeTrafficHeavyColor
368-
case "severe":
369-
return alternativeTrafficSevereColor
370-
default:
371-
return alternativeTrafficUnknownColor
372-
}
347+
switch congestionLevel {
348+
case "low":
349+
return isMain ? trafficLowColor : alternativeTrafficLowColor
350+
case "moderate":
351+
return isMain ? trafficModerateColor : alternativeTrafficModerateColor
352+
case "heavy":
353+
return isMain ? trafficHeavyColor : alternativeTrafficHeavyColor
354+
case "severe":
355+
return isMain ? trafficSevereColor : alternativeTrafficSevereColor
356+
default:
357+
return isMain ? trafficUnknownColor : alternativeTrafficUnknownColor
373358
}
374359
}
375360

Sources/MapboxNavigation/NavigationMapView.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ open class NavigationMapView: UIView {
5858
/**
5959
Controls whether to show congestion levels on alternative route lines. Defaults to `false`.
6060

61-
If `true` and there're multiple routes to choose, the alternative route lines would display the congestion levels at different colors, similar to the main route. To customize the congestion colors that represent different congestion levels, override the `alternativeTrafficUnknownColor` , `alternativeTrafficLowColor`, `alternativeTrafficModerateColor`, `alternativeTrafficHeavyColor`, `alternativeTrafficSevereColor` property for the `NavigationMapView.appearance()`.
61+
If `true` and there're multiple routes to choose, the alternative route lines would display the congestion levels at different colors, similar to the main route. To customize the congestion colors that represent different congestion levels, override the `alternativeTrafficUnknownColor`, `alternativeTrafficLowColor`, `alternativeTrafficModerateColor`, `alternativeTrafficHeavyColor`, `alternativeTrafficSevereColor` property for the `NavigationMapView.appearance()`.
6262
*/
63-
public var showsAlternativeCongestion: Bool = false
63+
public var showsCongestionForAlternativeRoutes: Bool = false
6464

6565
enum IdentifierType: Int {
6666
case source
@@ -647,10 +647,8 @@ open class NavigationMapView: UIView {
647647
lineLayer.layout?.lineJoin = .constant(.round)
648648
lineLayer.layout?.lineCap = .constant(.round)
649649

650-
if showsAlternativeCongestion {
651-
if let gradientStops = routeLineGradient(route, fractionTraveled: 0.0, isMain: false) {
652-
lineLayer.paint?.lineGradient = .expression((Expression.routeLineGradientExpression(gradientStops)))
653-
}
650+
if showsCongestionForAlternativeRoutes, let gradientStops = routeLineGradient(route, fractionTraveled: 0.0, isMain: false) {
651+
lineLayer.paint?.lineGradient = .expression((Expression.routeLineGradientExpression(gradientStops)))
654652
}
655653
mapView.style.addLayer(layer: lineLayer, layerPosition: LayerPosition(below: parentLayerIndentifier))
656654

0 commit comments

Comments
 (0)