diff options
author | Jason Wray <jason@mapbox.com> | 2018-05-21 21:51:11 -0400 |
---|---|---|
committer | Jason Wray <jason@mapbox.com> | 2018-05-21 22:08:07 -0400 |
commit | 41551d520e67b7e6ca816f9c120b2bedffae9762 (patch) | |
tree | cc16e2a8d3d90066768b6ff24e9be956cd255378 | |
parent | 78fdf5c7716ee7c79800b51713f30f1772514dc6 (diff) | |
download | qtlocation-mapboxgl-41551d520e67b7e6ca816f9c120b2bedffae9762.tar.gz |
[ios] Use standard callout positioning for unanimated user location changesupstream/fb-user-location-callout-positioning
Animated changes to the position of the user location annotation view still need to also handle updating its callout view, otherwise the two can become out of sync.
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index e16411f2c5..7786d11a21 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -3582,7 +3582,7 @@ public: return MGLAnnotationTagNotFound; } - return _annotationTagsByAnnotation.at(annotation); + return _annotationTagsByAnnotation.at(annotation); } - (void)addAnnotation:(id <MGLAnnotation>)annotation @@ -5753,21 +5753,18 @@ public: if (tag != MGLAnnotationTagNotFound) { MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(tag); annotationView = annotationContext.annotationView; + } else if (annotation == self.userLocation) { + annotationView = self.userLocationAnnotationView; } - CGRect rect = [self positioningRectForCalloutForAnnotationWithTag:tag]; + CGRect positioningRect = annotationView ? annotationView.frame : [self positioningRectForCalloutForAnnotationWithTag:tag]; - if (annotationView) - { - rect = annotationView.frame; - } + NSAssert( ! CGRectIsNull(positioningRect), @"Positioning rect should not be CGRectNull by this point"); - NSAssert(!CGRectIsNull(rect), @"Positioning rect should not be CGRectNull by this point"); + CGPoint centerPoint = CGPointMake(CGRectGetMidX(positioningRect), CGRectGetMinY(positioningRect)); - CGPoint point = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect)); - - if ( ! CGPointEqualToPoint(calloutView.center, point)) { - calloutView.center = point; + if ( ! CGPointEqualToPoint(calloutView.center, centerPoint)) { + calloutView.center = centerPoint; } } } @@ -5840,19 +5837,6 @@ public: annotationView.hidden = NO; [annotationView update]; - - if (_userLocationAnnotationIsSelected) - { - // Ensure the callout view still points to its annotation. - UIView <MGLCalloutView> *calloutView = self.calloutViewForSelectedAnnotation; - CGRect calloutFrame = calloutView.frame; - calloutFrame.origin.x = annotationView.center.x - CGRectGetWidth(calloutFrame) / 2; - calloutFrame.origin.y = CGRectGetMinY(annotationView.frame) - CGRectGetHeight(calloutFrame); - if ( ! CGRectEqualToRect(calloutView.frame, calloutFrame)) - { - calloutView.frame = calloutFrame; - } - } } else { |