diff options
author | Julian Rex <julian.rex@gmail.com> | 2018-09-26 12:19:26 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-26 12:19:26 -0400 |
commit | a9959773128f57e05f278d4d67ea167b8b6f73f5 (patch) | |
tree | 145b749e37b3af6d9f94697124704f6b279960b9 | |
parent | e6111a888e780789830daeae6634b90624fdb1e5 (diff) | |
download | qtlocation-mapboxgl-a9959773128f57e05f278d4d67ea167b8b6f73f5.tar.gz |
[ios] Fix for user location annotation jittering (and view annotations lagging) (#12895)
-rw-r--r-- | platform/darwin/src/MGLFoundation.h | 7 | ||||
-rw-r--r-- | platform/ios/CHANGELOG.md | 1 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 41 |
3 files changed, 33 insertions, 16 deletions
diff --git a/platform/darwin/src/MGLFoundation.h b/platform/darwin/src/MGLFoundation.h index 3400c63979..be86bb92f9 100644 --- a/platform/darwin/src/MGLFoundation.h +++ b/platform/darwin/src/MGLFoundation.h @@ -3,3 +3,10 @@ #import <Foundation/Foundation.h> #define MGL_EXPORT __attribute__((visibility ("default"))) + +/* Using a compound statement (GNU Extension, supported by clang) */ +#define MGL_OBJC_DYNAMIC_CAST(object, type) \ + ({ \ + __typeof__( object ) temp##__LINE__ = (object); \ + (type *)([temp##__LINE__ isKindOfClass:[type class]] ? temp##__LINE__ : nil); \ + }) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 194d17fda0..7c391c9f22 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -8,6 +8,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Added an `MGLSymbolStyleLayer.symbolZOrder` property for forcing point features in a symbol layer to be layered in the same order that they are specified in the layer’s associated source. ([#12783](https://github.com/mapbox/mapbox-gl-native/pull/12783)) * Fixed a crash when a style layer `*-pattern` property evaluates to nil for a particular feature. ([#12896](https://github.com/mapbox/mapbox-gl-native/pull/12896)) +* Fixed an issue with view annotations (including the user location annotation) and the GL map lagging relative to each other. ([#12895](https://github.com/mapbox/mapbox-gl-native/pull/12895)) ### Offline maps diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 92d3724b03..d550a086cb 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -636,6 +636,9 @@ public: _glView.layer.opaque = _opaque; _glView.delegate = self; + CAEAGLLayer *eaglLayer = MGL_OBJC_DYNAMIC_CAST(_glView.layer, CAEAGLLayer); + eaglLayer.presentsWithTransaction = YES; + [_glView bindDrawable]; [self insertSubview:_glView atIndex:0]; _glView.contentMode = UIViewContentModeCenter; @@ -985,8 +988,6 @@ public: if ( ! self.dormant || ! _rendererFrontend) { _rendererFrontend->render(); - - [self updateUserLocationAnnotationView]; } } @@ -1117,6 +1118,11 @@ public: { _needsDisplayRefresh = NO; + // Update UIKit elements, prior to rendering + [self updateUserLocationAnnotationView]; + [self updateAnnotationViews]; + [self updateCalloutView]; + [self.glView display]; } @@ -5709,8 +5715,7 @@ public: _isChangingAnnotationLayers = NO; [self.style didChangeValueForKey:@"layers"]; } - [self updateAnnotationViews]; - [self updateCalloutView]; + if ([self.delegate respondsToSelector:@selector(mapViewDidFinishRenderingFrame:fullyRendered:)]) { [self.delegate mapViewDidFinishRenderingFrame:self fullyRendered:fullyRendered]; @@ -5767,9 +5772,6 @@ public: return; } - [CATransaction begin]; - [CATransaction setDisableActions:YES]; - // If the map is pitched consider the viewport to be exactly the same as the bounds. // Otherwise, add a small buffer. CGFloat largestWidth = MAX(_largestAnnotationViewSize.width, CGRectGetWidth(self.frame)); @@ -5864,8 +5866,6 @@ public: } } } - - [CATransaction commit]; } - (void)updateCalloutView @@ -5951,12 +5951,8 @@ public: { // Smoothly move the user location annotation view and callout view to // the new location. - [UIView animateWithDuration:duration - delay:0 - options:(UIViewAnimationOptionCurveLinear | - UIViewAnimationOptionAllowUserInteraction | - UIViewAnimationOptionBeginFromCurrentState) - animations:^{ + + dispatch_block_t animation = ^{ if (self.selectedAnnotation == self.userLocation) { UIView <MGLCalloutView> *calloutView = self.calloutViewForSelectedAnnotation; @@ -5965,7 +5961,20 @@ public: userPoint.y - annotationView.center.y); } annotationView.center = userPoint; - } completion:NULL]; + }; + + if (duration > 0) { + [UIView animateWithDuration:duration + delay:0 + options:(UIViewAnimationOptionCurveLinear | + UIViewAnimationOptionAllowUserInteraction | + UIViewAnimationOptionBeginFromCurrentState) + animations:animation + completion:NULL]; + } + else { + animation(); + } _userLocationAnimationCompletionDate = [NSDate dateWithTimeIntervalSinceNow:duration]; annotationView.hidden = NO; |