summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2019-01-08 11:50:06 -0500
committerJulian Rex <julian.rex@mapbox.com>2019-01-08 12:21:03 -0500
commit1aa6dfa6f0870c4f96f7ea1d29ae928b6968be0c (patch)
treeaff546c006ea82d9134f92039ca2a2fd1b90bc6e
parent9e3a64970f161cbc10043766c51a13136753d158 (diff)
downloadqtlocation-mapboxgl-1aa6dfa6f0870c4f96f7ea1d29ae928b6968be0c.tar.gz
[ios] Renamed parameters/methods moveOnscreen for clarity.
Fixed bug where animateSelection was always YES in selectAnnotation:animated:
-rw-r--r--platform/ios/src/MGLMapView.h22
-rw-r--r--platform/ios/src/MGLMapView.mm35
2 files changed, 37 insertions, 20 deletions
diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h
index fd433fe1b3..afa2051716 100644
--- a/platform/ios/src/MGLMapView.h
+++ b/platform/ios/src/MGLMapView.h
@@ -1415,14 +1415,16 @@ MGL_EXPORT IB_DESIGNABLE
/**
Selects an annotation and displays its callout view.
- The `animated` parameter determines whether the map is panned to bring the
- annotation on-screen, specifically:
-
+ The `animated` parameter determines whether the selection is animated including whether the map is
+ panned to bring the annotation into view, specifically:
+
| `animated` parameter | Effect |
|------------------|--------|
- | `NO` | The annotation is selected, and the callout is presented. However the map is not panned to bring the annotation or callout onscreen. The presentation of the callout is animated. |
- | `YES` | The annotation is selected, and the callout is presented. If the annotation is offscreen *and* is of type `MGLPointAnnotation`, the map is panned so that the annotation and its callout are brought just onscreen. The annotation is *not* centered within the viewport. |
+ | `NO` | The annotation is selected, and the callout is presented. However the map is not panned to bring the annotation or callout into view. The presentation of the callout is NOT animated. |
+ | `YES` | The annotation is selected, and the callout is presented. If the annotation is not visible (or is partially visible) *and* is of type `MGLPointAnnotation`, the map is panned so that the annotation and its callout are brought into view. The annotation is *not* centered within the viewport. |
+ Note that a selection initiated by a single tap gesture is always animated.
+
@param annotation The annotation object to select.
@param animated If `YES`, the annotation and callout view are animated on-screen.
@@ -1432,6 +1434,16 @@ MGL_EXPORT IB_DESIGNABLE
- (void)selectAnnotation:(id <MGLAnnotation>)annotation animated:(BOOL)animated;
/**
+ :nodoc:
+ Selects an annotation and displays its callout view.
+
+ @param annotation The annotation object to select.
+ @param moveIntoView If the annotation is not visible (or is partially visible) *and* is of type `MGLPointAnnotation`, the map is panned so that the annotation and its callout are brought into view. The annotation is *not* centered within the viewport. |
+ @param animateSelection If `YES`, the annotation's selection state and callout view's presentation are animated.
+ */
+- (void)selectAnnotation:(id <MGLAnnotation>)annotation moveIntoView:(BOOL)moveIntoView animateSelection:(BOOL)animateSelection;
+
+/**
Deselects an annotation and hides its callout view.
@param annotation The annotation object to deselect.
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 52bf4e83f5..4d4bf39123 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -1768,7 +1768,7 @@ public:
{
CGPoint calloutPoint = [singleTap locationInView:self];
CGRect positionRect = [self positioningRectForAnnotation:annotation defaultCalloutPoint:calloutPoint];
- [self selectAnnotation:annotation moveOnscreen:YES animateSelection:YES calloutPositioningRect:positionRect];
+ [self selectAnnotation:annotation moveIntoView:YES animateSelection:YES calloutPositioningRect:positionRect];
}
else if (self.selectedAnnotation)
{
@@ -4525,7 +4525,7 @@ public:
}
-- (BOOL)isBringingAnnotationOnscreenSupportedForAnnotation:(id<MGLAnnotation>)annotation animated:(BOOL)animated {
+- (BOOL)isMovingAnnotationIntoViewSupportedForAnnotation:(id<MGLAnnotation>)annotation animated:(BOOL)animated {
// Consider delegating
return animated && [annotation isKindOfClass:[MGLPointAnnotation class]];
}
@@ -4577,12 +4577,17 @@ public:
- (void)selectAnnotation:(id <MGLAnnotation>)annotation animated:(BOOL)animated
{
- MGLLogDebug(@"Selecting annotation: %@ animated: %@", annotation, MGLStringFromBOOL(animated));
+ [self selectAnnotation:annotation moveIntoView:animated animateSelection:animated];
+}
+
+- (void)selectAnnotation:(id <MGLAnnotation>)annotation moveIntoView:(BOOL)moveIntoView animateSelection:(BOOL)animateSelection
+{
+ MGLLogDebug(@"Selecting annotation: %@ moveIntoView: %@ animateSelection: %@", annotation, MGLStringFromBOOL(moveIntoView), MGLStringFromBOOL(animateSelection));
CGRect positioningRect = [self positioningRectForAnnotation:annotation defaultCalloutPoint:CGPointZero];
- [self selectAnnotation:annotation moveOnscreen:animated animateSelection:YES calloutPositioningRect:positioningRect];
+ [self selectAnnotation:annotation moveIntoView:moveIntoView animateSelection:animateSelection calloutPositioningRect:positioningRect];
}
-- (void)selectAnnotation:(id <MGLAnnotation>)annotation moveOnscreen:(BOOL)moveOnscreen animateSelection:(BOOL)animateSelection calloutPositioningRect:(CGRect)calloutPositioningRect
+- (void)selectAnnotation:(id <MGLAnnotation>)annotation moveIntoView:(BOOL)moveIntoView animateSelection:(BOOL)animateSelection calloutPositioningRect:(CGRect)calloutPositioningRect
{
if ( ! annotation) return;
@@ -4617,8 +4622,8 @@ public:
self.selectedAnnotation = annotation;
// Determine if we're allowed to move this offscreen annotation on screen, even though we've asked it to
- if (moveOnscreen) {
- moveOnscreen = [self isBringingAnnotationOnscreenSupportedForAnnotation:annotation animated:animateSelection];
+ if (moveIntoView) {
+ moveIntoView = [self isMovingAnnotationIntoViewSupportedForAnnotation:annotation animated:animateSelection];
}
// If we have an invalid positioning rect, we need to provide a suitable default.
@@ -4702,15 +4707,15 @@ public:
// If the callout view provides inset (outset) information, we can use it to expand our positioning
// rect, which we then use to help move the annotation on-screen if want need to.
- if (moveOnscreen && [calloutView respondsToSelector:@selector(marginInsetsHintForPresentationFromRect:)]) {
+ if (moveIntoView && [calloutView respondsToSelector:@selector(marginInsetsHintForPresentationFromRect:)]) {
UIEdgeInsets margins = [calloutView marginInsetsHintForPresentationFromRect:calloutPositioningRect];
expandedPositioningRect = UIEdgeInsetsInsetRect(expandedPositioningRect, margins);
}
}
- if (moveOnscreen)
+ if (moveIntoView)
{
- moveOnscreen = NO;
+ moveIntoView = NO;
// Need to consider the content insets.
CGRect bounds = UIEdgeInsetsInsetRect(self.bounds, self.contentInset);
@@ -4719,23 +4724,23 @@ public:
if (CGRectGetMinX(calloutPositioningRect) < CGRectGetMinX(bounds))
{
constrainedRect.origin.x = expandedPositioningRect.origin.x;
- moveOnscreen = YES;
+ moveIntoView = YES;
}
else if (CGRectGetMaxX(calloutPositioningRect) > CGRectGetMaxX(bounds))
{
constrainedRect.origin.x = CGRectGetMaxX(expandedPositioningRect) - constrainedRect.size.width;
- moveOnscreen = YES;
+ moveIntoView = YES;
}
if (CGRectGetMinY(calloutPositioningRect) < CGRectGetMinY(bounds))
{
constrainedRect.origin.y = expandedPositioningRect.origin.y;
- moveOnscreen = YES;
+ moveIntoView = YES;
}
else if (CGRectGetMaxY(calloutPositioningRect) > CGRectGetMaxY(bounds))
{
constrainedRect.origin.y = CGRectGetMaxY(expandedPositioningRect) - constrainedRect.size.height;
- moveOnscreen = YES;
+ moveIntoView = YES;
}
}
@@ -4756,7 +4761,7 @@ public:
[self.delegate mapView:self didSelectAnnotationView:annotationView];
}
- if (moveOnscreen)
+ if (moveIntoView)
{
CGPoint center = CGPointMake(CGRectGetMidX(constrainedRect), CGRectGetMidY(constrainedRect));
CLLocationCoordinate2D centerCoord = [self convertPoint:center toCoordinateFromView:self];