summaryrefslogtreecommitdiff
path: root/platform/ios/src/MGLMapView.mm
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@gmail.com>2018-04-24 11:01:04 -0400
committerGitHub <noreply@github.com>2018-04-24 11:01:04 -0400
commit5b5549d644d026e093243b13e0770b9d34172ef9 (patch)
tree58aa4bc9cbc7cd78f00f4b2aed38570a21568717 /platform/ios/src/MGLMapView.mm
parentfa6c6a3733323e855c1b825c9546093200cf0d62 (diff)
downloadqtlocation-mapboxgl-5b5549d644d026e093243b13e0770b9d34172ef9.tar.gz
[ios, macos] Fix for camera movement when selecting visible annotations (#11731)
Diffstat (limited to 'platform/ios/src/MGLMapView.mm')
-rw-r--r--platform/ios/src/MGLMapView.mm21
1 files changed, 18 insertions, 3 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index b7d0974872..c679979d37 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -4290,6 +4290,15 @@ public:
moveOnscreen = [self isBringingAnnotationOnscreenSupportedForAnnotation:annotation animated:animateSelection];
}
+ // If we have an invalid positioning rect, we need to provide a suitable default.
+ // This (currently) happens if you select an annotation that has NOT yet been
+ // added. See https://github.com/mapbox/mapbox-gl-native/issues/11476
+ if (CGRectIsNull(calloutPositioningRect)) {
+ CLLocationCoordinate2D origin = annotation.coordinate;
+ CGPoint originPoint = [self convertCoordinate:origin toPointToView:self];
+ calloutPositioningRect = { .origin = originPoint, .size = CGSizeZero };
+ }
+
CGRect expandedPositioningRect = UIEdgeInsetsInsetRect(calloutPositioningRect, MGLMapViewOffscreenAnnotationPadding);
// Used for callout positioning, and moving offscreen annotations onscreen.
@@ -4442,7 +4451,11 @@ public:
{
MGLAnnotationTag annotationTag = [self annotationTagForAnnotation:annotation];
CGRect positioningRect = [self positioningRectForCalloutForAnnotationWithTag:annotationTag];
-
+
+ if (CGRectIsNull(positioningRect)) {
+ return positioningRect;
+ }
+
// For annotations which `coordinate` falls offscreen it will use the current tap point as anchor instead.
if ( ! CGRectIntersectsRect(positioningRect, self.bounds) && annotation != self.userLocation)
{
@@ -4462,15 +4475,15 @@ public:
id <MGLAnnotation> annotation = [self annotationWithTag:annotationTag];
if ( ! annotation)
{
- return CGRectZero;
+ return CGRectNull;
}
if ([annotation isKindOfClass:[MGLMultiPoint class]]) {
CLLocationCoordinate2D origin = annotation.coordinate;
CGPoint originPoint = [self convertCoordinate:origin toPointToView:self];
return CGRectMake(originPoint.x, originPoint.y, MGLAnnotationImagePaddingForHitTest, MGLAnnotationImagePaddingForHitTest);
-
}
+
UIImage *image = [self imageOfAnnotationWithTag:annotationTag].image;
if ( ! image)
{
@@ -5743,6 +5756,8 @@ public:
rect = annotationView.frame;
}
+ NSAssert(!CGRectIsNull(rect), @"Positioning rect should not be CGRectNull by this point");
+
CGPoint point = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect));
if ( ! CGPointEqualToPoint(calloutView.center, point)) {