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

Sticky course view tracking and persistent content inset #2047

Merged
merged 9 commits into from
Mar 23, 2019

Conversation

frederoni
Copy link
Contributor

@frederoni frederoni commented Mar 20, 2019

work in progress

This PR brings back the course tracking similar to the default in MGLMapView where the puck and camera are synchronized which is really noticeable when simulating faster than 1×.

tracking

cc @1ec5 @JThramer

@frederoni frederoni added the ⚠️ DO NOT MERGE PR should not be merged! label Mar 20, 2019

if overviewing {
let padding = UIEdgeInsets(top: 40, left: 40, bottom: 40, right: 40)
contentInsets += padding
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Max MBRouteLineWidthByZoomLevel should be accounted for.

UIView.animate(withDuration: duration, delay: 0, options: [.curveLinear, .beginFromCurrentState], animations: {
self.userCourseView?.center = self.convert(location.coordinate, toPointTo: self)
userCourseView?.center = userAnchorPoint
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

This reprises part of #1732. I take it #1732 (comment) is no longer a concern because the puck’s on-screen position is a fixed value now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly. The position is fixed unless frame by frame tracking is enabled which is needed when content insets or device orientation changes.

if overviewing {
let courseView = mapView.userCourseView != nil ? mapView.userCourseView!.bounds.midX : 0
let routeLineWidths = MBRouteLineWidthByZoomLevel.compactMap { $0.value.constantValue as? Int }
let maxRouteLineWidth = CGFloat(routeLineWidths.max() ?? 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

The resulting zoom level is the only one that matters, right?

@1ec5
Copy link
Contributor

1ec5 commented Mar 22, 2019

#2030 was already fixed in #2022.

@1ec5
Copy link
Contributor

1ec5 commented Mar 22, 2019

Apparently this issue regresses #2030 fitting the camera to the route during preview, but it should be straightforward to isolate and undo that change.

@1ec5
Copy link
Contributor

1ec5 commented Mar 22, 2019

Current state of this branch when previewing a route to a nearby destination using a search result in search history:

preview

@frederoni frederoni force-pushed the fred/course-view-edge-pad branch from a6edd1e to e79599c Compare March 22, 2019 20:46
@frederoni
Copy link
Contributor Author

frederoni commented Mar 22, 2019

The CarPlay preview is reverted and should behave exactly as before, .carPlayContentInsets(forOverviewing:) is only used when trackingUserCourse i set to true.

@@ -587,8 +587,7 @@ extension CarPlayManager: CPMapTemplateDelegate {
topDownCamera.pitch = 0
mapView.setCamera(topDownCamera, animated: false)

let padding = NavigationMapView.defaultPadding + mapView.safeArea
mapView.showcase([route], padding: padding)

This comment was marked as resolved.

@frederoni frederoni force-pushed the fred/course-view-edge-pad branch 3 times, most recently from e01d000 to e9450fc Compare March 22, 2019 21:38
Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

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

Things to add to the changelog:

  • Fixed an issue where the user puck moved around onscreen while tracking the user’s location.
  • Fixed an issue where the user puck briefly moved away from the route line as the user completed a turn.


if !tracksUserCourse {
mapView.setContentInset(overviewContentInsets(), animated: false)
mapView.fit(to: navigationService.route, facing: 0, padding: .zero, animated: false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Now if the user pans, disabling course tracking but without entering overview mode, the map will revert to course tracking once the navigation bar goes away. I guess that’s OK but somewhat unexpected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. We probably need a flag isOverviewing here similar to RouteMapViewController.
Panning around is currently not possible either with course tracking on/off nor overviewing (navigation bar popping in triggers viewSafeAreaInsetsDidChange() which in turn, fits the camera to the route).

Copy link
Contributor

Choose a reason for hiding this comment

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

@JThramer pointed out that this is actually pretty fortuitous. There isn’t a Resume or Recenter button like in NavigationViewController, and there’s no location tracking button like during the CarPlay browsing activity, so this code path is actually the most convenient way to get back into course tracking mode. Otherwise, the user has to tap the Overview button and tap the location tracking button after that.

currentCamera.pitch = 0
currentCamera.heading = 0

let newCamera = camera(currentCamera, fitting: line, edgePadding: padding)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is equivalent to calling cameraThatFits(_:direction:edgePadding:), since we’re forcing the pitch to be 0° anyways.

insets += NavigationMapView.courseViewMinimumInsets

let routeLineWidths = MBRouteLineWidthByZoomLevel.compactMap { $0.value.constantValue as? Int }
insets += UIEdgeInsets(floatLiteral: Double(routeLineWidths.max() ?? 0))
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 As noted in #2047 (comment), this is rather conservative considering that only one zoom level is active at a given time. But we don‘t have ready access to the evaluated expression (unlike if we were using GL JS), and this method also gets called before calculating a camera rather than after, so choosing the right width isn’t worth the hassle. In practice, it would only be a few extra points on each side at most.

@frederoni frederoni force-pushed the fred/course-view-edge-pad branch from f6e640b to 0326e45 Compare March 22, 2019 23:49
@JThramer JThramer removed the ⚠️ DO NOT MERGE PR should not be merged! label Mar 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants