summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-01-17 22:51:39 -0800
committerMinh Nguyễn <mxn@1ec5.org>2016-01-20 11:02:31 -0800
commit59f2c53c267ccb891b3eee12b91fd39df3b81d8a (patch)
treefc75e9e1bbfce391d5b8d85d4b1503a13aefe034 /platform
parent867e01581c8211b73d1fb0263e2eebaf9e3198b0 (diff)
downloadqtlocation-mapboxgl-59f2c53c267ccb891b3eee12b91fd39df3b81d8a.tar.gz
[ios] Keep callout attached to moving user dot
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/src/MGLMapView.mm44
1 files changed, 32 insertions, 12 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 9e511c4892..3dc06baabe 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -781,8 +781,9 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
{
[self updateHeadingForDeviceOrientation];
[self updateCompass];
- [self updateUserLocationAnnotationView];
}
+
+ [self updateUserLocationAnnotationView];
}
/// Updates `contentInset` to reflect the current window geometry.
@@ -2969,7 +2970,8 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
_userTrackingMode = mode;
if (_userTrackingMode == MGLUserTrackingModeNone
- || _userTrackingMode == MGLUserTrackingModeFollowWithCourse) {
+ || _userTrackingMode == MGLUserTrackingModeFollowWithCourse)
+ {
self.userTrackingState = MGLUserTrackingStatePossible;
}
@@ -3290,8 +3292,7 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
case mbgl::MapChangeRegionWillChange:
case mbgl::MapChangeRegionWillChangeAnimated:
{
- id <MGLAnnotation> selectedAnnotation = self.selectedAnnotation;
- if (selectedAnnotation != self.userLocation
+ if ( ! _userLocationAnnotationIsSelected
|| self.userTrackingMode == MGLUserTrackingModeNone
|| self.userTrackingState != MGLUserTrackingStateChanged)
{
@@ -3391,12 +3392,13 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
- (void)updateUserLocationAnnotationView
{
+ MGLUserLocationAnnotationView *annotationView = self.userLocationAnnotationView;
if ( ! CLLocationCoordinate2DIsValid(self.userLocation.coordinate)) {
- self.userLocationAnnotationView.layer.hidden = YES;
+ annotationView.layer.hidden = YES;
return;
}
- if ( ! self.userLocationAnnotationView.superview) [self.glView addSubview:self.userLocationAnnotationView];
+ if ( ! annotationView.superview) [self.glView addSubview:annotationView];
CGPoint userPoint;
if (self.userTrackingMode != MGLUserTrackingModeNone
@@ -3412,15 +3414,33 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
if (CGRectContainsPoint(CGRectInset(self.bounds, -MGLAnnotationUpdateViewportOutset.width,
-MGLAnnotationUpdateViewportOutset.height), userPoint))
{
- self.userLocationAnnotationView.center = userPoint;
-
- self.userLocationAnnotationView.layer.hidden = NO;
-
- [self.userLocationAnnotationView setupLayers];
+ annotationView.center = userPoint;
+ annotationView.layer.hidden = NO;
+ [annotationView setupLayers];
+
+ 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
{
- self.userLocationAnnotationView.layer.hidden = YES;
+ // User has moved far enough outside of the viewport that showing it or
+ // its callout would be useless.
+ annotationView.layer.hidden = YES;
+
+ if (_userLocationAnnotationIsSelected)
+ {
+ [self deselectAnnotation:self.selectedAnnotation animated:YES];
+ }
}
}