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

Fix building highlighting when changing style. #2550

Closed

Conversation

MaximAlien
Copy link
Contributor

Closing #2545.

@MaximAlien MaximAlien added bug Something isn’t working UI Work related to visual components, Android Auto, Camera, 3D, voice, etc. labels Aug 18, 2020
@MaximAlien MaximAlien added this to the v1.0.0 milestone Aug 18, 2020
@MaximAlien MaximAlien requested review from 1ec5 and Udumft August 18, 2020 23:18
@MaximAlien MaximAlien self-assigned this Aug 18, 2020
@MaximAlien MaximAlien linked an issue Aug 19, 2020 that may be closed by this pull request
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.

In my opinion, the operations that take place inside the style observation in this PR should take place in whatever class uses NavigationMapView, be it RouteMapViewController or something custom. As it is, I don’t think it’s a huge burden on a custom view controller to call show(_:), showWaypoints(on:), and highlightBuildings(at:in3D:).

I would readily agree that it’s unfortunate that runtime styling customizations get blown away when changing the style, but that’s a broader map SDK limitation that would be better addressed by MGLMapView automatically reapplying runtime styling changes, as in mapbox/mapbox-gl-native#6180.

@@ -266,6 +276,20 @@ open class NavigationMapView: MGLMapView, UIGestureRecognizerDelegate {
addGestureRecognizer(mapTapGesture)

installUserCourseView()

styleObservation = observe(\.style, options: .new) { [weak self] (mapView, change) in
Copy link
Contributor

@1ec5 1ec5 Aug 19, 2020

Choose a reason for hiding this comment

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

Does observing a key path on self cause the map view to retain itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so. As per docs here Neither the object receiving this message, nor observer, are retained.

Comment on lines +284 to +267
if let routes = self.routes, let currentRoute = routes.first {
self.show(routes)
self.showWaypoints(on: currentRoute)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to gradually reduce the usage of NavigationMapView.routes. We’ve successfully removed NavigationMapView’s listening for route progress change. In the same vein, we should aim to remove extra state that the map view keeps around that could easily get out of sync with RouteController.

Copy link
Contributor Author

@MaximAlien MaximAlien Aug 22, 2020

Choose a reason for hiding this comment

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

Not sure that in such case there is an easy way to prevent using routes variable. Since show(_:legIndex:) is public method and NavigationMapView is also independent class there should be a way to persist current routes (to allow routes selection on tap, etc).

@MaximAlien
Copy link
Contributor Author

In my opinion, the operations that take place inside the style observation in this PR should take place in whatever class uses NavigationMapView, be it RouteMapViewController or something custom. As it is, I don’t think it’s a huge burden on a custom view controller to call show(_:), showWaypoints(on:), and highlightBuildings(at:in3D:).

I would readily agree that it’s unfortunate that runtime styling customizations get blown away when changing the style, but that’s a broader map SDK limitation that would be better addressed by MGLMapView automatically reapplying runtime styling changes, as in mapbox/mapbox-gl-native#6180.

I agree that current fix solves broader maps problem best fix for which would be in Maps SDK. On the other hand current behavior brings not really good UX, since those who're just getting familiar with the Navigation SDK might encounter it without any prior knowledge of why annotations are staying on map view whereas routes and waypoints do not.

Since there was not that much movement in mapbox/mapbox-gl-native#6180 for the past few years It'd probably be better to keep current fix and add FIXME note which points to ticket in mapbox-gl-native. What do you think?

@MaximAlien MaximAlien force-pushed the maxim/2545-fix-building-highlight-when-changing-style branch from 5d4b6bf to 8e624d7 Compare September 11, 2020 18:52
@1ec5
Copy link
Contributor

1ec5 commented Sep 11, 2020

current behavior brings not really good UX, since those who're just getting familiar with the Navigation SDK might encounter it without any prior knowledge of why annotations are staying on map view whereas routes and waypoints do not.

On the one hand, I see how it’s unintuitive that changing the style clears out runtime styling changes, but on the other hand, we can only solve so much of that issue. The developer is free to apply their own runtime styling changes, so the navigation SDK can only reapply part of the runtime styling changes for them. We’d do so clumsily by enforcing a z-order that the developer might not want.

I think I’d still prefer that we move the style observation to RouteMapViewController or NavigationViewController, where it’s already a normal thing to observe the style. Then we could add something to the documentation for show(_:legIndex:) etc. that reiterates that these methods’ changes need to be reapplied when switching styles, for the case where a developer implements a standalone map or custom navigation UI and needs to call these methods directly.

/ref #2545 (comment)

@1ec5
Copy link
Contributor

1ec5 commented Sep 11, 2020

On the other other hand, changing the style currently seems to get routes out of sync with what’s visually on the map. Since routes is private, there’s no recourse other than remembering to call removeRoutes() or show(_:legIndex:). So at a minimum, we do need to observe the styleURL key path and clear out routes if it changes.

@1ec5 1ec5 modified the milestones: v1.0.0, v1.1.0 Sep 21, 2020
@IodaMikeMapbox IodaMikeMapbox added the needs discussion Can't be started in current state, needs clarification. label Sep 29, 2020
@1ec5 1ec5 changed the base branch from master to main October 7, 2020 18:17
@1ec5 1ec5 modified the milestones: v1.1.0, v1.2.0 Oct 16, 2020
@MaximAlien MaximAlien added the iOS label Oct 30, 2020
@MaximAlien
Copy link
Contributor Author

Current PR is no longer relevant.

@MaximAlien MaximAlien closed this Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn’t working needs discussion Can't be started in current state, needs clarification. 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.

Route and highlighted building are removed after changing style.
3 participants