Skip to content

Commit

Permalink
Hide portions of the route that the user has passed (#2377)
Browse files Browse the repository at this point in the history
  • Loading branch information
captainbarbosa authored Jun 25, 2020
1 parent 489a12d commit e890ae7
Show file tree
Hide file tree
Showing 7 changed files with 438 additions and 120 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@
* Fixed an issue where spoken and visual instructions sometimes omitted the cardinal direction after a route number in the United States. ([valhalla/valhalla#1917](https://github.com/valhalla/valhalla/pull/1917))
* A spoken instruction about an exit ramp no longer specifies the side of the road if the ramp branches off the slow lane (on the right side in regions that drive on the right). ([valhalla/valhalla#1990](https://github.com/valhalla/valhalla/pull/1990))

## Map

* Removed `NavigationMapViewDelegate.navigationMapView(_:routeStyleLayerWithIdentifier:source:)`, `NavigationMapViewDelegate.navigationMapView(_:routeCasingStyleLayerWithIdentifier:source:)` in favor of four new delegate methods to customize the route styling ([#2377](https://github.com/mapbox/mapbox-navigation-ios/pull/2377)):
* `NavigationMapViewDelegate.navigationMapView(_:mainRouteStyleLayerWithIdentifier:source:)` to style the main route.
* `NavigationMapViewDelegate.navigationMapView(_:mainRouteCasingStyleLayerWithIdentifier:source:)` to style the casing of the main route.
* `NavigationMapViewDelegate.navigationMapView(_:alternativeRouteStyleLayerWithIdentifier:source:)` to style alternative routes.
* `NavigationMapViewDelegate.navigationMapView(_:alternativeRouteCasingStyleLayerWithIdentifier:source:)` to style the casing of alternative routes.
* Added the ability for the route line to disappear as the puck travels along a route during turn-by-turn navigation. ([#2377](https://github.com/mapbox/mapbox-navigation-ios/pull/2377))
* Fixed an issue where the casing for the main route would not overlap alternative routes. ([#2377](https://github.com/mapbox/mapbox-navigation-ios/pull/2377))

## v0.40.0

### Packaging
Expand Down
2 changes: 2 additions & 0 deletions MapboxNavigation/DayStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extension UIColor {
class var defaultRouteLayer: UIColor { get { return #colorLiteral(red: 0.337254902, green: 0.6588235294, blue: 0.9843137255, alpha: 1) } }
class var defaultAlternateLine: UIColor { get { return #colorLiteral(red: 0.6, green: 0.6, blue: 0.6, alpha: 1) } }
class var defaultAlternateLineCasing: UIColor { get { return #colorLiteral(red: 0.5019607843, green: 0.4980392157, blue: 0.5019607843, alpha: 1) } }
class var defaultTraversedRouteColor: UIColor { get { return #colorLiteral(red: 1, green: 1, blue: 1, alpha: 0) } }
class var defaultManeuverArrowStroke: UIColor { get { return .defaultRouteLayer } }
class var defaultManeuverArrow: UIColor { get { return #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1) } }

Expand Down Expand Up @@ -116,6 +117,7 @@ open class DayStyle: Style {
NavigationMapView.appearance().maneuverArrowStrokeColor = .defaultManeuverArrowStroke
NavigationMapView.appearance().routeAlternateColor = .defaultAlternateLine
NavigationMapView.appearance().routeCasingColor = .defaultRouteCasing
NavigationMapView.appearance().traversedRouteColor = .defaultTraversedRouteColor
NavigationMapView.appearance().trafficHeavyColor = .trafficHeavy
NavigationMapView.appearance().trafficLowColor = .trafficLow
NavigationMapView.appearance().trafficModerateColor = .trafficModerate
Expand Down
367 changes: 296 additions & 71 deletions MapboxNavigation/NavigationMapView.swift

Large diffs are not rendered by default.

79 changes: 58 additions & 21 deletions MapboxNavigation/NavigationMapViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,46 @@ import MapboxCoreNavigation
The `NavigationMapViewDelegate` provides methods for configuring the NavigationMapView, as well as responding to events triggered by the NavigationMapView.
*/
public protocol NavigationMapViewDelegate: class, UnimplementedLogging {

/**
Asks the receiver to return an MGLStyleLayer for routes, given an identifier and source.
Asks the receiver to return an MGLStyleLayer for the main route line, given an identifier and source.
This method is invoked when the map view loads and any time routes are added.
- parameter mapView: The NavigationMapView.
- parameter identifier: The style identifier.
- parameter source: The Layer source containing the route data that this method would style.
- returns: An MGLStyleLayer that the map applies to all routes.
*/
func navigationMapView(_ mapView: NavigationMapView, routeStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer?
- parameter source: The source containing the route data that this method would style.
- returns: An MGLStyleLayer that is applied to the main route line.
*/
func navigationMapView(_ mapView: NavigationMapView, mainRouteStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer?

/**
Asks the receiver to return an MGLStyleLayer for the casing layer that surrounds main route line, given an identifier and source.
This method is invoked when the map view loads and any time routes are added.
- parameter mapView: The NavigationMapView.
- parameter identifier: The style identifier.
- parameter source: The source containing the route data that this method would style.
- returns: An MGLStyleLayer that is applied as a casing around the main route line.
*/
func navigationMapView(_ mapView: NavigationMapView, mainRouteCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer?

/**
Asks the receiver to return an MGLStyleLayer for the alternative route lines, given an identifier and source.
This method is invoked when the map view loads and any time routes are added.
- parameter mapView: The NavigationMapView.
- parameter identifier: The style identifier.
- parameter source: The source containing the route data that this method would style.
- returns: An MGLStyleLayer that is applied to alternative routes.
*/
func navigationMapView(_ mapView: NavigationMapView, alternativeRouteStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer?

/**
Asks the receiver to return an MGLStyleLayer for the casing layer that surrounds alternative route lines, given an identifier and source.
This method is invoked when the map view loads and any time routes are added.
- parameter mapView: The NavigationMapView.
- parameter identifier: The style identifier.
- parameter source: The source containing the route data that this method would style.
- returns: An MGLStyleLayer that is applied as a casing around alternative route lines.
*/
func navigationMapView(_ mapView: NavigationMapView, alternateRouteCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer?

/**
Asks the receiver to return an MGLStyleLayer for waypoints, given an identifier and source.
Expand All @@ -36,17 +67,6 @@ public protocol NavigationMapViewDelegate: class, UnimplementedLogging {
*/
func navigationMapView(_ mapView: NavigationMapView, waypointSymbolStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer?

/**
Asks the receiver to return an MGLStyleLayer for route casings, given an identifier and source.
This method is invoked when the map view loads and anytime routes are added.
- note: Specify a casing to ensure good contrast between the route line and the underlying map layers.
- parameter mapView: The NavigationMapView.
- parameter identifier: The style identifier.
- parameter source: The Layer source containing the route data that this method would style.
- returns: An MGLStyleLayer that the map applies to the route.
*/
func navigationMapView(_ mapView: NavigationMapView, routeCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer?

/**
Tells the receiver that the user has selected a route by interacting with the map view.
- parameter mapView: The NavigationMapView.
Expand Down Expand Up @@ -98,34 +118,51 @@ public protocol NavigationMapViewDelegate: class, UnimplementedLogging {
}

public extension NavigationMapViewDelegate {

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func navigationMapView(_ mapView: NavigationMapView, routeStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
func navigationMapView(_ mapView: NavigationMapView, mainRouteStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
logUnimplemented(protocolType: NavigationMapViewDelegate.self, level: .debug)
return nil
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func navigationMapView(_ mapView: NavigationMapView, waypointStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
func navigationMapView(_ mapView: NavigationMapView, mainRouteCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
logUnimplemented(protocolType: NavigationMapViewDelegate.self, level: .debug)
return nil
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func navigationMapView(_ mapView: NavigationMapView, alternativeRouteStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
logUnimplemented(protocolType: NavigationMapViewDelegate.self, level: .debug)
return nil
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func navigationMapView(_ mapView: NavigationMapView, alternateRouteCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
logUnimplemented(protocolType: NavigationMapViewDelegate.self, level: .debug)
return nil
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func navigationMapView(_ mapView: NavigationMapView, waypointSymbolStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
func navigationMapView(_ mapView: NavigationMapView, waypointStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
logUnimplemented(protocolType: NavigationMapViewDelegate.self, level: .debug)
return nil
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func navigationMapView(_ mapView: NavigationMapView, routeCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
func navigationMapView(_ mapView: NavigationMapView, waypointSymbolStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
logUnimplemented(protocolType: NavigationMapViewDelegate.self, level: .debug)
return nil
}
Expand Down
19 changes: 14 additions & 5 deletions MapboxNavigation/NavigationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,21 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter

//MARK: - RouteMapViewControllerDelegate
extension NavigationViewController: RouteMapViewControllerDelegate {
public func navigationMapView(_ mapView: NavigationMapView, routeCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
return delegate?.navigationViewController(self, routeCasingStyleLayerWithIdentifier: identifier, source: source)

public func navigationMapView(_ mapView: NavigationMapView, mainRouteStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
return delegate?.navigationViewController(self, mainRouteStyleLayerWithIdentifier: identifier, source: source)
}

public func navigationMapView(_ mapView: NavigationMapView, routeStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
return delegate?.navigationViewController(self, routeStyleLayerWithIdentifier: identifier, source: source)

public func navigationMapView(_ mapView: NavigationMapView, mainRouteCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
return delegate?.navigationViewController(self, mainRouteCasingStyleLayerWithIdentifier: identifier, source: source)
}

public func navigationMapView(_ mapView: NavigationMapView, alternativeRouteStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
return delegate?.navigationViewController(self, alternativeRouteStyleLayerWithIdentifier: identifier, source: source)
}

public func navigationMapView(_ mapView: NavigationMapView, alternateRouteCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
return delegate?.navigationViewController(self, alternateRouteCasingStyleLayerWithIdentifier: identifier, source: source)
}

public func navigationMapView(_ mapView: NavigationMapView, didSelect route: Route) {
Expand Down
58 changes: 40 additions & 18 deletions MapboxNavigation/NavigationViewControllerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,35 @@ public protocol NavigationViewControllerDelegate: VisualInstructionDelegate{
- parameter error: An error raised during the process of obtaining a new route.
*/
func navigationViewController(_ navigationViewController: NavigationViewController, didFailToRerouteWith error: Error)



/**
Returns an `MGLStyleLayer` that determines the appearance of the route line.
Returns an `MGLStyleLayer` that determines the appearance of the main route line.
If this method is unimplemented, the navigation view controller’s map view draws the route line using an `MGLLineStyleLayer`.
*/
func navigationViewController(_ navigationViewController: NavigationViewController, routeStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer?
*/
func navigationViewController(_ navigationViewController: NavigationViewController, mainRouteStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer?

/**
Returns an `MGLStyleLayer` that determines the appearance of the route line’s casing.
If this method is unimplemented, the navigation view controller’s map view draws the route line’s casing using an `MGLLineStyleLayer` whose width is greater than that of the style layer returned by `navigationViewController(_:routeStyleLayerWithIdentifier:source:)`.
*/
func navigationViewController(_ navigationViewController: NavigationViewController, routeCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer?
Returns an `MGLStyleLayer` that determines the appearance of the casing around the main route line.
If this method is unimplemented, the navigation view controller’s map view draws the casing for the main route line using an `MGLLineStyleLayer`.
*/
func navigationViewController(_ navigationViewController: NavigationViewController, mainRouteCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer?

/**
Returns an `MGLStyleLayer` that determines the appearance of alternative route lines.
If this method is unimplemented, the navigation view controller’s map view draws the alternative route lines using an `MGLLineStyleLayer`.
*/
func navigationViewController(_ navigationViewController: NavigationViewController, alternativeRouteStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer?

/**
Returns an `MGLStyleLayer` that determines the appearance of the casing around the alternative route lines.
If this method is unimplemented, the navigation view controller’s map view draws the casing for the alternative route lines using an `MGLLineStyleLayer`.
*/
func navigationViewController(_ navigationViewController: NavigationViewController, alternateRouteCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer?

/**
Returns an `MGLShape` that represents the path of the route line.
Expand Down Expand Up @@ -243,19 +258,26 @@ public extension NavigationViewControllerDelegate {
func navigationViewController(_ navigationViewController: NavigationViewController, didFailToRerouteWith error: Error) {
logUnimplemented(protocolType: NavigationViewControllerDelegate.self, level: .debug)
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func navigationViewController(_ navigationViewController: NavigationViewController, routeStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
func navigationViewController(_ navigationViewController: NavigationViewController, mainRouteStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
logUnimplemented(protocolType: NavigationViewControllerDelegate.self, level: .debug)
return nil
}

/**
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
*/
func navigationViewController(_ navigationViewController: NavigationViewController, routeCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {

func navigationViewController(_ navigationViewController: NavigationViewController, mainRouteCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
logUnimplemented(protocolType: NavigationViewControllerDelegate.self, level: .debug)
return nil
}

func navigationViewController(_ navigationViewController: NavigationViewController, alternativeRouteStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
logUnimplemented(protocolType: NavigationViewControllerDelegate.self, level: .debug)
return nil
}

func navigationViewController(_ navigationViewController: NavigationViewController, alternateRouteCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? {
logUnimplemented(protocolType: NavigationViewControllerDelegate.self, level: .debug)
return nil
}
Expand Down
Loading

0 comments on commit e890ae7

Please sign in to comment.