-
Notifications
You must be signed in to change notification settings - Fork 314
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
Allow styling each route differently #2719
Conversation
d7570b5
to
24b6799
Compare
let routeShape = navigationMapViewDelegate?.navigationMapView(self, shapeFor: [route]) ?? | ||
shape(for: route, legIndex: legIndex, isAlternateRoute: false) | ||
|
||
let routeSource = addRouteSource(style, identifier: routeSourceIdentifier, shape: routeShape) | ||
|
||
let mainRouteLayer = addMainRouteLayer(style, | ||
source: routeSource, | ||
identifier: routeIdentifier, | ||
lineGradient: routeLineGradient(route, fractionTraveled: 0.0)) | ||
|
||
let mainRouteCasingShape = navigationMapViewDelegate?.navigationMapView(self, simplifiedShapeFor: route) ?? | ||
shape(forCasingOf: route, legIndex: legIndex) | ||
|
||
let routeCasingSource = addRouteSource(style, identifier: routeCasingSourceIdentifier, shape: mainRouteCasingShape) | ||
|
||
parentLayer = addMainRouteCasingLayer(style, | ||
source: routeCasingSource, | ||
identifier: routeCasingIdentifier, | ||
lineGradient: routeCasingGradient(0.0), | ||
below: mainRouteLayer) | ||
|
||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the most important change. As documentation was slightly changed in #2623 to address that NavigationMapViewDelegate.navigationMapView(_:shapeFor:)
and NavigationMapViewDelegate.navigationMapView(_:simplifiedShapeFor:)
are meant to be used only for main route in comment:
Resulting `MGLShape` will then be styled using `NavigationMapView.navigationMapView(_: mainRouteStyleLayerWithIdentifier: source:)` provided style or a default congestion style if above delegate method was not implemented. In latter case, consider modifing your custom `MGLShape` `attributes` to have 'isAlternateRoute' key set to 'false'. Otherwise style predicate condition will filter out the shape.
I think it has become more misleading, as NavigationMapViewDelegate.navigationMapView(_:shapeFor:)
allows to change shape not only for main route, but for all routes.
After adding the ability to provide route style for every route in this PR NavigationMapViewDelegate.navigationMapView(_:shapeFor:)
and NavigationMapViewDelegate.navigationMapView(_:simplifiedShapeFor:)
will be called only for main route, this means there will be no ability to provide custom shape for alternative routes and their casings.
Because of this I think NavigationMapViewDelegate.navigationMapView(_:shapeFor:)
can be updated to be similar to NavigationMapViewDelegate.navigationMapView(_:simplifiedShapeFor:)
and provide Route
instead of [Route]
, but it'd break public API.
@1ec5, @Udumft please let me know if that sounds reasonable and any changes are needed.
Example app was also updated to showcase the ability to provide custom layers and shapes in mapbox/mapbox-navigation-ios-examples#83.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of this I think
NavigationMapViewDelegate.navigationMapView(_:shapeFor:)
can be updated to be similar toNavigationMapViewDelegate.navigationMapView(_:simplifiedShapeFor:)
and provideRoute
instead of[Route]
, but it'd break public API.
We can add a new delegate method and deprecate the old one, as long as the old one continues to function reasonably appropriately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To play it safe I'm inclined to leave current implementation without adding new/deprecating old APIs: end user will be able to change shape only for main route instead of all routes (main + alternative). This will match current docs as well.
a88d5cb
to
98e86fe
Compare
98e86fe
to
92b7f24
Compare
@@ -469,62 +468,101 @@ open class NavigationMapView: MGLMapView, UIGestureRecognizerDelegate { | |||
*/ | |||
public func show(_ routes: [Route], legIndex: Int = 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@1ec5, do you remember how legIndex
can be used here? As I can see after adding vanishing route line functionality it's no longer used when creating shape for the route, and the only place I can see where it was used before was to control public let MBCurrentLegAttribute = "isCurrentLeg"
property inMGLPolylineFeature
.
After running few tests I don't see that setting isCurrentLeg
attribute to true
or false
affects anything though (I think idea was to use it in route line styling).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to add a changelog entry. Thanks!
Initial implementation of route line styling functionality. Example: