[Bug]: navigationMapView.showRouteDuration(along:) is poorly positioned and color is not switching upon tapping alternative route
Mapbox Navigation SDK version
2.6.0
Steps to reproduce
Start a navigationViewController and give it the property navigationMapView?.showRouteDurations(along: routeResponse.routes). Then start the active navigation and tap on alternative Route.
Expected behavior
-The Label showing the duration for each route should be positioned dynamically, like in other navigation services to avoid being hidden by the users position or to avoid overlapping with other labels of the same type. It should be more or less positioned in the center of the part of the route currently seen in the navigation view. -The position the label aims at should be somewhere on the route, not beside it. -There should always be a label showing the duration for every alternative shown on the map -When tapping on an alternative Route, the blue label should turn white and the white label (former alternative route duration label) should turn blue, to indicate that this is the currently selected route.
Actual behavior
- The Labels are poorly positioned and are sometimes hidden by overlapping labels or even by the users navigation puck.
- The label aims somewhere beside the route and does not touch the route, which would make more sense.
- Some labels are positioned in a way in which it is not 100% clear to which route they belong (see screenshot below), because they are pointing to a part of the route that is also part of the alternative route
- Sometimes, alternative routes don't show any duration labels. Even the main route is sometimes missing the label
- The labels don't switch color, as to be seen in the screenshots below:
Before tapping the alternatve route:
After tapping the alternative route:
Is this a one-time issue or a repeatable issue?
repeatable
The Labels are poorly positioned and are sometimes hidden by overlapping labels or even by the users navigation puck.
As of #2734, the map SDK didn’t expose any API for determining where a label is positioned, so instead it literally chooses a random location along a certain portion of the route to place the callout. The randomness helps to reduce the occurrence of multiple callouts overlapping each other but doesn’t make it easy to avoid other elements, such as the puck.
In a related conversation for #4133, @ShanMa1991 pointed out that, more recently, MapboxMap.queryRenderedFeatures(at:options:completion:) does return the label’s backing feature when you query for features at the label, even if the label is offset considerably from the feature in the source. This isn’t quite the same as knowing where the rendering engine thinks the optimal placement position would be, but it would allow us to detect collisions and overlaps more manually and reposition the callout if so.
The label aims somewhere beside the route and does not touch the route, which would make more sense.
Unfortunately, this is a known issue stemming from mapbox/mapbox-maps-ios#381.
The labels don't switch color, as to be seen in the screenshots below:
Indeed, this is a bug. Tapping on the route line in NavigationViewController’s map view only switches the current route:
https://github.com/mapbox/mapbox-navigation-ios/blob/a7b037a3291d369ff1194686ee054899610068af/Sources/MapboxNavigation/NavigationViewController.swift#L1300-L1304
whereas the same gesture in the example application’s main map view explicitly refreshes waypoints and duration annotations:
https://github.com/mapbox/mapbox-navigation-ios/blob/c2d62334eb0bccf2e2ef0a58a33deaf9593bbd09/Example/ViewController.swift#L724-L727 https://github.com/mapbox/mapbox-navigation-ios/blob/c2d62334eb0bccf2e2ef0a58a33deaf9593bbd09/Example/ViewController.swift#L61-L65 https://github.com/mapbox/mapbox-navigation-ios/blob/c2d62334eb0bccf2e2ef0a58a33deaf9593bbd09/Example/ViewController.swift#L76-L78
/cc @alexshalamov @Udumft @MaximAlien
The Labels are poorly positioned and are sometimes hidden by overlapping labels or even by the users navigation puck.
There’s also a compounding bug in the placement code that’ll be fixed by #4176.