Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make vanishing route opt-in #2418

Merged
merged 1 commit into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions MapboxNavigation/NavigationMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ open class NavigationMapView: MGLMapView, UIGestureRecognizerDelegate {
Maximum distance the user can tap for a selection to be valid when selecting an alternate route.
*/
public var tapGestureDistanceThreshold: CGFloat = 50

/**
Controls whether the route disappears as the user location
puck travels over it. Defaults to `false`.

If `true`, the route line behind the user location puck
will fade to full transparancy. To customize the fade color that
appears behind the traveled section of a route, override the
`vanishingRouteColor` property for the `NavigationMapView.appearance()`.
*/
public var fadesRouteDuringNavigation: Bool = false

/**
The object that acts as the navigation delegate of the map view.
Expand Down Expand Up @@ -508,6 +519,7 @@ open class NavigationMapView: MGLMapView, UIGestureRecognizerDelegate {
func mainRouteStyleLayer(identifier: String, source: MGLSource) -> MGLLineStyleLayer {
let mainRouteLayer = MGLLineStyleLayer(identifier: identifier, source: source)
mainRouteLayer.predicate = NSPredicate(format: "isAlternateRoute == false")
// Default color if no traffic is enabled
mainRouteLayer.lineColor = NSExpression(forConstantValue: trafficUnknownColor)
mainRouteLayer.lineWidth = NSExpression(format: "mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", MBRouteLineWidthByZoomLevel)
mainRouteLayer.lineJoin = NSExpression(forConstantValue: "round")
Expand All @@ -522,6 +534,7 @@ open class NavigationMapView: MGLMapView, UIGestureRecognizerDelegate {
func mainRouteCasingStyleLayer(identifier: String, source: MGLSource) -> MGLLineStyleLayer {
let mainRouteCasingLayer = MGLLineStyleLayer(identifier: identifier, source: source)
mainRouteCasingLayer.predicate = NSPredicate(format: "isAlternateRoute == false")
// Default color if no traffic is enabled
mainRouteCasingLayer.lineColor = NSExpression(forConstantValue: routeCasingColor)
mainRouteCasingLayer.lineWidth = NSExpression(format: "mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", MBRouteLineWidthByZoomLevel.multiplied(by: 1.5))
mainRouteCasingLayer.lineJoin = NSExpression(forConstantValue: "round")
Expand Down
4 changes: 3 additions & 1 deletion MapboxNavigation/RouteMapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@ extension RouteMapViewController: NavigationComponent {
let legIndex = progress.legIndex
let stepIndex = progress.currentLegProgress.stepIndex

mapView.fadeRoute(progress.fractionTraveled)
if mapView.fadesRouteDuringNavigation {
mapView.fadeRoute(progress.fractionTraveled)
}

mapView.updatePreferredFrameRate(for: progress)
if currentLegIndexMapped != legIndex {
Expand Down