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

Add the ability to show specific route leg with color overriding #2833

Merged
merged 6 commits into from
Apr 29, 2021

Conversation

ShanMa1991
Copy link
Contributor

@ShanMa1991 ShanMa1991 commented Feb 25, 2021

Description

In 1.x , we're not dealing with the legIndex as in 0.4. This pr is to port the ability to handle specific legIndex for mapView route line.

The way we specify the leg index and change the route layer color should be like following:

navigationMapView.routeCasingColor = UIColor.red
navigationMapView.trafficUnknownColor = UIColor.blue
navigationMapView.show([route], legIndex: 1)

The color could be override. If we don't specify the leg Index, the whole route would show congestion color. But if we specify the leg index, only the specified legIndex would show the congestion color, while other legs would show the routeCasingColor.

  • allow to show specific route leg
  • allow to show current route leg during turn-by-turn navigation with overriding color
  • update the changeLog

Implementation

When generating the congestion features for the whole route, the CurrentLegAttribute of the feature property would represent whether this leg is the specified leg. If the route leg is not specified, or it is the specified one, it would be true.

Then during the generation of the gradient stops for the route layer, if the CurrentLegAttribute is true, we have congestion color, if not, we're using the routeCasingColor.

Screenshots or Gifs

The following is how we show specific route leg with with

navigationMapView.routeCasingColor = UIColor.red
navigationMapView.trafficUnknownColor = UIColor.blue
navigationMapView.show([route], legIndex: 1)

showLeg1

The following is that during turn-by turn navigation, the current route leg would be specified with the color overriding. The default specified leg would be the current leg, which is the same as in the 0.4.

navigationViewController.navigationMapView.routeCasingColor = UIColor.red
navigationViewController.navigationMapView.trafficUnknownColor = UIColor.blue

navigationCurrent

@ShanMa1991 ShanMa1991 added UI Work related to visual components, Android Auto, Camera, 3D, voice, etc. iOS labels Feb 25, 2021
@ShanMa1991
Copy link
Contributor Author

Now the problem is that the layer and source could be added from the FeatureCollection with right color and opacity. But when the navigation start, the route lines become invisible. I'll work on this issue.

@MaximAlien MaximAlien force-pushed the maxim/add-navigation-map-view-delegates branch 2 times, most recently from 0f2852c to af02181 Compare March 3, 2021 00:27
@ShanMa1991
Copy link
Contributor Author

Fix the opacity expression, now it could allow the overriding route leg color. But it has a problem to display the following vanishing vision during navigation. It seems that there's something wrong with the gradient stops which cause the route line fading away at random place

randomVanishing

Besides, to make sure both of the vanishing route line and route overriding work, the next step is to update the fractiontravled method. Because we only need to get the current leg display the vanishing feature, the fractiontravled should be calculated on each leg. The other leg's color should only depend on congestion level and opacity.

@ShanMa1991 ShanMa1991 marked this pull request as ready for review March 4, 2021 02:30
@MaximAlien MaximAlien force-pushed the maxim/add-navigation-map-view-delegates branch from af02181 to 59e7ba4 Compare March 4, 2021 18:05
@ShanMa1991
Copy link
Contributor Author

ShanMa1991 commented Mar 5, 2021

So now the problem is caused by several reasons:

  1. The line gradient applied to each Feature, not the FeatureCollection. For example, if we have the following gradient stops, as below, and the line is formed with a FeatureCollection, with 2 Feature inside. It will display 2 seperate lines below:
                let gradientStops:[Double: UIColor] =  [
                    0: UIColor.blue,
                    0.5.nextDown: UIColor.blue,
                    0.5: UIColor.red,
                    1: UIColor.red
                ]

multiFeature

  1. The func congestionFeatures(legIndex:, roadClassesWithOverriddenCongestionLevels: is creating multiple feature for even one-leg route. And it cause the congestion level and gradient not working as expected. For example, if we do the let routeFeatures = FeatureCollection(features: [Feature(route.shape!)]) and have a gradient at the median as following:

When we have one feature FeatureCollection, we could still see the color presented for the line gradient as below:
expected

The next step is to:

  1. fix the func congestionFeatures(legIndex:, roadClassesWithOverriddenCongestionLevels: to make sure the route line source of FeatureCollection is generated with one feature for each route leg.
  2. The gradient stops for vanishing route line should only applies to the current route leg, and the fractiontraveled should also be based on the current route leg.

@MaximAlien MaximAlien force-pushed the maxim/add-navigation-map-view-delegates branch 2 times, most recently from 75f05fa to 95cfca9 Compare March 8, 2021 23:03
@MaximAlien MaximAlien force-pushed the maxim/add-navigation-map-view-delegates branch 4 times, most recently from bf37f96 to 0c2ec50 Compare March 10, 2021 19:00
@ShanMa1991
Copy link
Contributor Author

Due to the FeatureCollection generated whole route line layer couldn't support the line-gradient , as discussed in https://github.com/mapbox/mapbox-maps-ios-internal/issues/396 and https://github.com/mapbox/mapbox-maps-ios-internal/issues/396. the next step is to generate one Feature for each route leg, and a list of Feature would be used to represent the route line. It would allow the vanishing is happening on the current leg, and the overriding of route line style based on leg index.

@MaximAlien MaximAlien force-pushed the maxim/add-navigation-map-view-delegates branch 3 times, most recently from e1b511d to 2a42cb9 Compare March 23, 2021 18:11
@MaximAlien MaximAlien force-pushed the maxim/add-navigation-map-view-delegates branch 7 times, most recently from fbfccd0 to 14e77fa Compare April 22, 2021 00:46
@MaximAlien MaximAlien force-pushed the maxim/add-navigation-map-view-delegates branch 3 times, most recently from a7e38ee to cf57162 Compare April 26, 2021 18:40
@MaximAlien MaximAlien force-pushed the maxim/add-navigation-map-view-delegates branch from cf57162 to bca8d5a Compare April 27, 2021 17:42
Base automatically changed from maxim/add-navigation-map-view-delegates to release-v2.0 April 27, 2021 20:09
@ShanMa1991 ShanMa1991 requested review from MaximAlien and a team April 28, 2021 22:35
@ShanMa1991 ShanMa1991 changed the title Add legIndex specified mapView route line delegate Add the ability to show specific route leg with color overriding Apr 29, 2021
Copy link
Contributor

@MaximAlien MaximAlien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested with NavigationMapView and with standalone NavigationViewController and it seems to work similarly to what was available in 0.40. It's great to see that fix turned out to be not really complex one.

CHANGELOG.md Outdated Show resolved Hide resolved
Sources/MapboxNavigation/NavigationMapView.swift Outdated Show resolved Hide resolved
@ShanMa1991 ShanMa1991 merged commit da66b40 into release-v2.0 Apr 29, 2021
@ShanMa1991 ShanMa1991 deleted the shan-show-leg-827 branch April 29, 2021 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
UI Work related to visual components, Android Auto, Camera, 3D, voice, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants