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 to use map SDK location layer during turn-by-turn navigation #2968
Conversation
When we call the |
Instead of creating a routeLine as a |
edcf6a6
to
46bed46
Compare
dd0e530
to
1a87cb2
Compare
2679994
to
273e4bc
Compare
Now the camera is shaking stronger than #2998, when in simulation mode during turn-by-turn navigation, the camera should only receive the |
8623ae0
to
eb4cd41
Compare
eb4cd41
to
3d85b8c
Compare
f81fe12
to
724e406
Compare
Because right now the mapSDK doesn't support the puck layer bearing rotation based on To handle this issue, the following cases are considered:
|
19573bc
to
dd9a263
Compare
4911d7e
to
c760794
Compare
Sources/MapboxNavigation/NavigationMapView+VanishingRouteLine.swift
Outdated
Show resolved
Hide resolved
let modelSourceCode = [NavigationMapView.ModelKeyIdentifier.modelSouce: model] | ||
if let data = try? JSONEncoder().encode(modelSourceCode), | ||
let jsonDictionary = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] { | ||
try? mapView.mapboxMap.style.setSourceProperty(for: NavigationMapView.SourceIdentifier.puck3DSource, property: "models", value: jsonDictionary) |
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.
Is it possible to use Model more directly, rather than serializing to JSON?
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 the source type of the 3D puck layer isModelSource
, which is internal and could not be updated directly.
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.
ModelSource became internal in mapbox/mapbox-maps-ios#198. I don’t see any rationale associated with it, so it might have been just for lack of external demand. ModelSource would be more type-safe and forward-compatible than raw JSON usage. Since this is how the map SDK currently requires you to use the models
property, let’s track ModelSource usage as tail work and also request an upstream change.
/cc @macdrevx
e86216e
to
a8cdf5b
Compare
do { | ||
try self.mapView.mapboxMap.style.updateLayer(withId: mainRouteLayerIdentifier) { (lineLayer: inout LineLayer) throws in | ||
let congestionSegments = routeProgress.route.congestionFeatures(legIndex: self.currentLegIndex, roadClassesWithOverriddenCongestionLevels: self.roadClassesWithOverriddenCongestionLevels) | ||
let mainRouteLayerGradient = self.routeLineGradient(congestionSegments, | ||
fractionTraveled: newFractionTraveled) | ||
|
||
lineLayer.lineGradient = .expression(Expression.routeLineGradientExpression(mainRouteLayerGradient)) | ||
} | ||
|
||
try self.mapView.mapboxMap.style.updateLayer(withId: mainRouteCasingLayerIdentifier) { (lineLayer: inout LineLayer) throws in | ||
let mainRouteCasingLayerGradient = self.routeLineGradient(fractionTraveled: newFractionTraveled) | ||
|
||
lineLayer.lineGradient = .expression(Expression.routeLineGradientExpression(mainRouteCasingLayerGradient)) | ||
} | ||
} catch { | ||
print("Failed to update main route line layer.") | ||
} |
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.
This is basically a duplicate of code in .default
case (other than newFractionTraveled
and fractionTraveled
properties usage). Can it be extracted into separate method?
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.
Thanks for the suggestion, I'll update the implementation of the vanishing route line.
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.
Due to the comment below, the vanishing route line method now is still using the Timer incase of overwhelming calculation.
This reverts commit 0fc027507a7459d5bdeb16dd502536e35772d69c.
After test, the another constraint that block using the frame to update vanishing route line is based on the following reason.
During the turn by turn navigation, if we zoom pretty close, and we have a following log of the time interval of the render frame finished:
That means that when we zoom pretty close and the route line would not be updated because the frame will not keep rendering update. There would show a tail of the route line behind the puck.
So based on the above reasons, the tail work of replacing the Timer of vanishing route line would be resolved and addressed in another separate ticket with the render frame rate improvement, or the rotation improvement. |
let modelSourceCode = [NavigationMapView.ModelKeyIdentifier.modelSouce: model] | ||
if let data = try? JSONEncoder().encode(modelSourceCode), | ||
let jsonDictionary = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] { | ||
try? mapView.mapboxMap.style.setSourceProperty(for: NavigationMapView.SourceIdentifier.puck3DSource, property: "models", value: jsonDictionary) |
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.
ModelSource became internal in mapbox/mapbox-maps-ios#198. I don’t see any rationale associated with it, so it might have been just for lack of external demand. ModelSource would be more type-safe and forward-compatible than raw JSON usage. Since this is how the map SDK currently requires you to use the models
property, let’s track ModelSource usage as tail work and also request an upstream change.
/cc @macdrevx
b69c6ed
to
cb5c0f1
Compare
The tail work of the vanishing route line implementation will be addressed in #3069 separately. |
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.
Overall, I’m concerned about special-casing specific location managers/providers to achieve the normal behavior, which could leave an application-defined location manager/provider with unexpected behavior despite conforming to the right protocols.
I’m approving this PR on the condition that simulatesLocation
be based on a property of the location manager class (via the NavigationLocationManager class and any necessary overrides), as discussed in #2968 (comment). I think that’s the minimum necessary to ensure that custom subclasses still work correctly. But we should investigate #2968 (comment) as tail work soon while there’s still time: having NavigationLocationManager conform to LocationProvider would be pretty elegant compared to the confusing and limiting PassiveLocationDataSource/PassiveLocationManager split we have now.
Description
This pr is to allow developer choose between UserCourseView and map SDK location layer.
UserHaloCourseView
andUserPuckCourseView
to open access and subclassable.Implementation
Added the ability to allow developers choose between
NavigationMapView.userCourseView
and map SDK location layer through theNavigationMapView.puckType
. The default puck is theNavigationMapView.userCourseView
. To configure a customized 2D Puck as following :To configure a customized 3D Puck as following:
To display the puck on NavigationMapView, use
navigationMapView.puckType = .puck3D(configuration: configuration)
.To display the puck during turn-by-turn navigation, use
navigationViewController.navigationMapView.puckType = .puck3D(configuration: configuration)
To allow the puck rotate under
PassiveLocationManager
, developers need to receiveNotification.passiveLocationDataSourceDidUpdate
and call thenavigationMapView.updateUserCourseView(location)
when there's a new location to adjust the rotation of the customized puck.Screenshots or Gifs
2D customized puck example during turn-by-turn navigation:
3D customized puck example during turn-by-turn navigation:
3D customized puck example under PassiveLocationManager: