-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[ios, macos] Display the shape annotation's callout when the center coordinate is offscreen. #10255
Conversation
1043955
to
98278e8
Compare
eaba3b3
to
6b54c0c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to the feedback below, please mention this change in the iOS and macOS changelogs. Thanks!
platform/ios/src/MGLMapView.mm
Outdated
[self selectAnnotation:annotation forGestureRegognizer:nil animated:animated]; | ||
} | ||
|
||
- (void)selectAnnotation:(id <MGLAnnotation>)annotation forGestureRegognizer:(UITapGestureRecognizer *)singleTap animated:(BOOL)animated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
singleTap
is being used only to determine where the callout should be anchored. This method should take a positioningRect
explicitly: -selectAnnotation:animated:calloutPositioningRect:
. The existing code that determines positioningRect
can live in -selectAnnotation:animated:
.
platform/ios/src/MGLMapView.mm
Outdated
positioningRect = annotationView.frame; | ||
[annotationView.superview bringSubviewToFront:annotationView]; | ||
[annotationView setSelected:YES animated:animated]; | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: extra set of curly braces.
platform/ios/src/MGLMapView.mm
Outdated
// The client can request that any annotation be selected (even ones that are offscreen). | ||
// The annotation can’t be selected if no part of it is hittable. | ||
// The client can request that any annotation be selected (even ones that are offscreen). | ||
// The annotation will bounce to the current tap point as anchor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment implies that the PR fixes #3249, but I don’t see anything that actually moves the camera. It’s the callout view that aligns with the tap point, not the annotation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'm trying to say is that if the annotation's center coordinate is outside the current viewport it will use the current tap position instead. Does this makes more sense?
// For annotations which `coordinate` falls offscreen it will use the current tap point as anchor instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That depends on whether the annotation is a point annotation or shape annotation:
The client can request that any annotation be selected, even an annotation that is off-screen. If a shape annotation is visible but its centroid is not, and a gesture recognizer is specified, the callout view is anchored to the gesture recognizer’s location.
platform/ios/src/MGLMapView.mm
Outdated
if ( ! CGRectIntersectsRect(positioningRect, self.bounds) && annotation != self.userLocation) | ||
{ | ||
return; | ||
CGPoint tapPoint = [singleTap locationInView:self]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
singleTap
isn’t guaranteed to exist at this point. If the developer calls -showAnnotation:animated:
, a public method, then tapPoint
ends up being (0, 0). It should instead be the annotation’s center coordinate.
platform/ios/src/MGLMapView.mm
Outdated
[self selectAnnotation:annotation forGestureRegognizer:nil animated:animated]; | ||
} | ||
|
||
- (void)selectAnnotation:(id <MGLAnnotation>)annotation forGestureRegognizer:(UITapGestureRecognizer *)singleTap animated:(BOOL)animated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: Regognizer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤣
platform/ios/src/MGLMapView.mm
Outdated
// The client can request that any annotation be selected (even ones that are offscreen). | ||
// The annotation can’t be selected if no part of it is hittable. | ||
// The client can request that any annotation be selected (even ones that are offscreen). | ||
// The annotation will bounce to the current tap point as anchor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That depends on whether the annotation is a point annotation or shape annotation:
The client can request that any annotation be selected, even an annotation that is off-screen. If a shape annotation is visible but its centroid is not, and a gesture recognizer is specified, the callout view is anchored to the gesture recognizer’s location.
…center is offscreen.
6b54c0c
to
87c8150
Compare
platform/ios/src/MGLMapView.mm
Outdated
@@ -4118,6 +4114,27 @@ - (MGLCompactCalloutView *)calloutViewForAnnotation:(id <MGLAnnotation>)annotati | |||
/// Returns the rectangle that represents the annotation image of the annotation | |||
/// with the given tag. This rectangle is fitted to the image’s alignment rect | |||
/// and is appropriate for positioning a popover. | |||
/// If a shape annotation is visible but its centroid is not, and a default point is specified, | |||
/// the callout view is anchored to the default callout point. | |||
- (CGRect)positioningRectForAnnotation:(id <MGLAnnotation>)annotation withDefaultCalloutPoint:(CGPoint)calloutPoint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: in general, it’s unnecessary to use a preposition for a parameter after the first parameter (“with” in this case).
d19df02
to
0713434
Compare
Fixes #10229