Skip to content

Commit 31ccf25

Browse files
committed
add ability to control whether to show congestion levels on alternative route lines, update changelog
1 parent d8f37dc commit 31ccf25

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +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))
2930

3031
### Location tracking
3132

Example/ViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class ViewController: UIViewController {
5757
}
5858

5959
startButton.isEnabled = true
60+
// Show congestion levels on alternative route lines if there're multiple routes in the response.
61+
navigationMapView.showsAlternativeCongestion = true
6062
navigationMapView.show(routes)
6163
navigationMapView.showWaypoints(on: currentRoute)
6264
}

Sources/MapboxNavigation/NavigationMapView+VanishingRouteLine.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ extension NavigationMapView {
217217
})
218218
}
219219

220-
func routeLineGradient(_ route: Route, fractionTraveled: Double, isMain: Bool) -> [Double: UIColor]? {
220+
func routeLineGradient(_ route: Route, fractionTraveled: Double, isMain: Bool = true) -> [Double: UIColor]? {
221221
var gradientStops = [CGFloat: UIColor]()
222222

223223
/**

Sources/MapboxNavigation/NavigationMapView.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ open class NavigationMapView: UIView {
5555
public var roadClassesWithOverriddenCongestionLevels: Set<MapboxStreetsRoadClass>? = nil
5656

5757
var cameraAnimator: CameraAnimator!
58+
/**
59+
Controls whether to show congestion levels on alternative route lines. Defaults to `false`.
60+
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()`.
62+
*/
63+
public var showsAlternativeCongestion: Bool = false
5864

5965
enum IdentifierType: Int {
6066
case source
@@ -558,7 +564,7 @@ open class NavigationMapView: UIView {
558564
lineLayer.layout?.lineJoin = .constant(.round)
559565
lineLayer.layout?.lineCap = .constant(.round)
560566

561-
if let gradientStops = routeLineGradient(route, fractionTraveled: fractionTraveledForStops, isMain: true) {
567+
if let gradientStops = routeLineGradient(route, fractionTraveled: fractionTraveledForStops) {
562568
lineLayer.paint?.lineGradient = .expression((Expression.routeLineGradientExpression(gradientStops)))
563569
}
564570

@@ -641,8 +647,10 @@ open class NavigationMapView: UIView {
641647
lineLayer.layout?.lineJoin = .constant(.round)
642648
lineLayer.layout?.lineCap = .constant(.round)
643649

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

0 commit comments

Comments
 (0)