Repository navigation
Expose mapView(:ViewForAnnotation:) - #498
Conversation
| } | ||
|
|
||
| func navigationMapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? { | ||
| guard annotation is MGLUserLocation else { return nil } |
There was a problem hiding this comment.
For some reason, I'm never getting an annotation with type MGLUserLocation .
There was a problem hiding this comment.
I wonder if this has to do with some of the user location overriding that the navigation SDK does…
There was a problem hiding this comment.
The reason is that MGLMapView.showsUserLocation is set during storyboard initialization, causing MGLMapView to call MGLMapViewDelegate.mapView(_:viewFor:). Unfortunately, navigationMapView isn’t set until much later.
There was a problem hiding this comment.
Filed mapbox/mapbox-gl-native#9781 to address the root cause.
| present(navigationViewController, animated: true, completion: nil) | ||
| } | ||
|
|
||
| func navigationMapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? { |
There was a problem hiding this comment.
This method should be implemented in the extension below that conforms to NavigationViewControllerDelegate.
| */ | ||
| @objc optional func navigationMapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? | ||
|
|
||
| @objc optional func navigationMapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? |
There was a problem hiding this comment.
This method needs documentation.
| } | ||
|
|
||
| func navigationMapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? { | ||
| guard annotation is MGLUserLocation else { return nil } |
There was a problem hiding this comment.
I wonder if this has to do with some of the user location overriding that the navigation SDK does…
|
This PR would fix #213. |
showsUserLocation preinitializes the user location annotation view very early on, but the delegate has yet to be set by that time, let alone the navigation map delegate. When each of the delegate properties is set, force the map view to reconsider everything it does as part of showing the user location.
| */ | ||
| func refreshShowsUserLocation() { | ||
| showsUserLocation = false | ||
| showsUserLocation = true |
There was a problem hiding this comment.
This will result in -[MGLMapView updateUserLocationAnnotationViewAnimatedWithDuration:] getting called a lot more frequently than before when setting up the map view. From a cursory glance, I don’t think it’ll be a problem in practice.
| /** | ||
| Returns a view object to mark the given point annotation object on the map. | ||
|
|
||
| The user location annotation view can also be customized via this method. When annotation is an instance of `MGLUserLocation` (or equal to the map view’s userLocation property), return an instance of `MGLUserLocationAnnotationView` (or a subclass thereof). |
There was a problem hiding this comment.
or equal to the map view’s userLocation property
The developer doesn’t have direct access to MGLMapView.userLocation, do they?
|
@1ec5 updated. |
This exposes the ability to provide a view for any annotation on the map. In the example, I show how to provide a view for the user puck.
/cc @1ec5 @frederoni @ericrwolfe