Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

[ios, macos] Display the shape annotation's callout when the center coordinate is offscreen. #10255

Merged
merged 2 commits into from
Nov 1, 2017

Conversation

fabian-guerra
Copy link
Contributor

@fabian-guerra fabian-guerra commented Oct 20, 2017

Fixes #10229

@fabian-guerra fabian-guerra force-pushed the fabian-center-callout-10229 branch from 1043955 to 98278e8 Compare October 23, 2017 19:00
@fabian-guerra fabian-guerra self-assigned this Oct 23, 2017
@fabian-guerra fabian-guerra force-pushed the fabian-center-callout-10229 branch 2 times, most recently from eaba3b3 to 6b54c0c Compare October 23, 2017 20:07
@fabian-guerra fabian-guerra requested review from 1ec5 and boundsj October 23, 2017 20:08
@fabian-guerra fabian-guerra added this to the ios-v3.7.0 milestone Oct 23, 2017
Copy link
Contributor

@1ec5 1ec5 left a 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!

[self selectAnnotation:annotation forGestureRegognizer:nil animated:animated];
}

- (void)selectAnnotation:(id <MGLAnnotation>)annotation forGestureRegognizer:(UITapGestureRecognizer *)singleTap animated:(BOOL)animated
Copy link
Contributor

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:.

positioningRect = annotationView.frame;
[annotationView.superview bringSubviewToFront:annotationView];
[annotationView setSelected:YES animated:animated];
{
Copy link
Contributor

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.

// 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.
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

if ( ! CGRectIntersectsRect(positioningRect, self.bounds) && annotation != self.userLocation)
{
return;
CGPoint tapPoint = [singleTap locationInView:self];
Copy link
Contributor

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.

[self selectAnnotation:annotation forGestureRegognizer:nil animated:animated];
}

- (void)selectAnnotation:(id <MGLAnnotation>)annotation forGestureRegognizer:(UITapGestureRecognizer *)singleTap animated:(BOOL)animated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: Regognizer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤣

// 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.
Copy link
Contributor

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.

@fabian-guerra fabian-guerra force-pushed the fabian-center-callout-10229 branch from 6b54c0c to 87c8150 Compare October 31, 2017 20:39
@@ -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
Copy link
Contributor

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).

@fabian-guerra fabian-guerra force-pushed the fabian-center-callout-10229 branch from d19df02 to 0713434 Compare November 1, 2017 02:21
@fabian-guerra fabian-guerra merged commit 63f7963 into release-agua Nov 1, 2017
@fabian-guerra fabian-guerra deleted the fabian-center-callout-10229 branch November 1, 2017 12:20
@fabian-guerra fabian-guerra changed the title [ios, macos] Center shape annotation's callout when offscreen. [ios, macos] Display the shape annotation's callout when the center coordinate is offscreen. Nov 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants