diff options
author | Julian Rex <julian.rex@mapbox.com> | 2018-04-18 20:12:45 -0400 |
---|---|---|
committer | Julian Rex <julian.rex@mapbox.com> | 2018-04-18 20:12:45 -0400 |
commit | 0dc5861e0e52aa02a863a834090addeddb1b0b00 (patch) | |
tree | f6d9483e1ed5368d81076e8dc91b233af69bffe6 | |
parent | 29e23cf08b4315cfa0777c6962f06376e2bdee60 (diff) | |
download | qtlocation-mapboxgl-0dc5861e0e52aa02a863a834090addeddb1b0b00.tar.gz |
Catch case where an invalid positioning rect is returned by `-positioningRectForCalloutForAnnotationWithTag:`
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 21 |
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)) { |