Repository navigation
User dot sometimes jitters during panning gesture #12740
Description
Sometimes, the user dot (user location annotation view) moves inconsistently as the user pans the map view from side to side; in other words, it sometimes darts forward or backtracks, producing a jarring jittering effect. To illustrate the problem, here’s a 30 fps recording at half speed (original screen recording):
This effect is distinct from the issue in #5489, in which the map view lags behind the annotation views but the annotation views move at a consistent rate. That issue also reproduces during camera animations driven by mbgl, such as drift animations following gestures. By contrast, this issue only reproduces during panning gestures, even slow ones in which the underlying map is able to move at a consistent rate. It’s fairly difficult to reproduce reliably: scrubbing the same map region repeatedly will reliably reproduce the issue, but then it’ll stop reproducing after you switch applications or stop interacting with the map for awhile.
The user dot differs from any other annotation view in that its center property is set inside an instantaneous UIView animation block that is triggered by -glkView:drawInRect: after telling mbgl to render a frame:
mapbox-gl-native/platform/ios/src/MGLMapView.mm
Lines 987 to 989 in d297bf1
| _rendererFrontend->render(); | |
| [self updateUserLocationAnnotationView]; |
mapbox-gl-native/platform/ios/src/MGLMapView.mm
Line 5743 in d297bf1
| [self updateUserLocationAnnotationViewAnimatedWithDuration:0]; |
mapbox-gl-native/platform/ios/src/MGLMapView.mm
Lines 5939 to 5953 in d297bf1
| [UIView animateWithDuration:duration | |
| delay:0 | |
| options:(UIViewAnimationOptionCurveLinear | | |
| UIViewAnimationOptionAllowUserInteraction | | |
| UIViewAnimationOptionBeginFromCurrentState) | |
| animations:^{ | |
| if (self.selectedAnnotation == self.userLocation) | |
| { | |
| UIView <MGLCalloutView> *calloutView = self.calloutViewForSelectedAnnotation; | |
| calloutView.frame = CGRectOffset(calloutView.frame, | |
| userPoint.x - annotationView.center.x, | |
| userPoint.y - annotationView.center.y); | |
| } | |
| annotationView.center = userPoint; | |
| } completion:NULL]; |
-glkView:drawInRect: is driven by a CADisplayLink, which #2985 proposes eliminating. (Optionally, -updateFromDisplayLink will also throttle rendering, but that functionality isn’t enabled here.)
Meanwhile, every other annotation view’s center property is set directly via -mapViewDidFinishRenderingFrameFullyRendered: after mbgl finishes rendering a frame:
mapbox-gl-native/platform/ios/src/MGLMapView.mm
Line 5805 in d297bf1
| annotationView.center = MGLPointRounded([self convertCoordinate:annotationContext.annotation.coordinate toPointToView:self]); |
-mapViewDidFinishRenderingFrameFullyRendered: can be called not only after -glkView:drawInRect: asks mbgl to render a frame but also after mbgl renders a frame on its own volition. Perhaps not coincidentally, I’ve only been able to reproduce this issue when labels fade in and out as I pan the map, as seen in the recording above. That fading is driven entirely by a timer in mbgl, as are the drift animations in #5489.
The iOS and macOS map SDKs use mbgl’s synchronous rendering path rather than the asynchronous rendering path that the Android map SDK uses. So on each frame rendered because of CADisplayLink, -updateAnnotationViews gets called before -updateUserLocationAnnotationView.
Configuration
Mapbox SDK versions: v4.3.0, but probably earlier
iOS/macOS versions: 11.4.1
Device/simulator models: iPhone 8
Xcode version: 10.0 beta 6
/ref #8874 (comment)
/cc @mapbox/maps-ios

Activity
1ec5 commentedon Aug 25, 2018
-[MGLFaux3DUserLocationAnnotationView updateFrameWithSize:]also sets thecenterproperty directly. This code is triggered by a call to-[MGLUserLocationAnnotationView update]right after the call to+[UIView animateWithDuration:delay:options:animations:completion:]in-[MGLMapView updateUserLocationAnnotationViewAnimatedWithDuration:]. Perhaps that-updatecall should go in the completion handler of+[UIView animateWithDuration:delay:options:animations:completion:], which is asynchronous even when it’s instantaneous.1ec5 commentedon Dec 10, 2018
Fixed in #12895.
julianrex commentedon Dec 10, 2018
I believe there may still be an issue if two simultaneous operations try to modify the user location at the same time (for example dragging the map while the being repositioned by location updates).
@1ec5 feel free to reopen should you notice this.Going to open a new ticket for the above if it turns out #13041 isn't sufficient.