summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2018-10-02 13:39:19 -0400
committerJulian Rex <julian.rex@mapbox.com>2018-10-06 00:58:40 -0400
commit2be56509a12c8ed67f95b9ec6ccd017a3ccf37e0 (patch)
treed531f1d0eb83ac0b180f161e09591fe282b90549
parent88bd36b65ca5f15d27470cd4f9b67ffa06fbdfac (diff)
downloadqtlocation-mapboxgl-2be56509a12c8ed67f95b9ec6ccd017a3ccf37e0.tar.gz
Updated anchor handling for shapes. Moved callout margin handling into callout delegate method.
-rw-r--r--platform/ios/src/MGLMapView.mm41
-rwxr-xr-xplatform/ios/vendor/SMCalloutView/SMCalloutView.m12
2 files changed, 43 insertions, 10 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 79fe9b8ea0..b6af3d552a 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -229,6 +229,12 @@ public:
/// Currently shown popover representing the selected annotation.
@property (nonatomic) UIView<MGLCalloutView> *calloutViewForSelectedAnnotation;
+
+/// Anchor coordinate from which to present callout views (for example, for shapes this
+/// could be the touch point rather than its centroid)
+@property (nonatomic) CLLocationCoordinate2D anchorCoordinateForSelectedAnnotation;
+
+
@property (nonatomic) MGLUserLocationAnnotationView *userLocationAnnotationView;
/// Indicates how thoroughly the map view is tracking the user location.
@@ -4423,7 +4429,8 @@ public:
calloutPositioningRect = { .origin = originPoint, .size = CGSizeZero };
}
- CGRect expandedPositioningRect = UIEdgeInsetsInsetRect(calloutPositioningRect, MGLMapViewOffscreenAnnotationPadding);
+
+ CGRect expandedPositioningRect = calloutPositioningRect;
// Used for callout positioning, and moving offscreen annotations onscreen.
CGRect constrainedRect = self.contentFrame;
@@ -4495,8 +4502,14 @@ 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:)]) {
- UIEdgeInsets margins = [calloutView marginInsetsHintForPresentationFromRect:calloutPositioningRect];
+ if (moveOnscreen) {
+
+ UIEdgeInsets margins = MGLMapViewOffscreenAnnotationPadding;
+
+ if ([calloutView respondsToSelector:@selector(marginInsetsHintForPresentationFromRect:)]) {
+ margins = [calloutView marginInsetsHintForPresentationFromRect:calloutPositioningRect];
+ }
+
expandedPositioningRect = UIEdgeInsetsInsetRect(expandedPositioningRect, margins);
}
}
@@ -4546,6 +4559,10 @@ public:
constrainedToRect:constrainedRect
animated:animated];
+ // Save the anchor coordinate
+ CGPoint anchorPoint = CGPointMake(CGRectGetMidX(calloutPositioningRect), CGRectGetMidY(calloutPositioningRect));
+ self.anchorCoordinateForSelectedAnnotation = [self convertPoint:anchorPoint toCoordinateFromView:self];
+
// notify delegate
if ([self.delegate respondsToSelector:@selector(mapView:didSelectAnnotation:)])
{
@@ -4561,6 +4578,7 @@ public:
{
CGPoint center = CGPointMake(CGRectGetMidX(constrainedRect), CGRectGetMidY(constrainedRect));
CLLocationCoordinate2D centerCoord = [self convertPoint:center toCoordinateFromView:self];
+
[self setCenterCoordinate:centerCoord animated:animated];
}
}
@@ -4610,8 +4628,18 @@ public:
return CGRectNull;
}
+ CLLocationCoordinate2D coordinate;
+
+ if ((annotation == self.selectedAnnotation) &&
+ CLLocationCoordinate2DIsValid(self.anchorCoordinateForSelectedAnnotation)) {
+ coordinate = self.anchorCoordinateForSelectedAnnotation;
+ }
+ else {
+ coordinate = annotation.coordinate;
+ }
+
if ([annotation isKindOfClass:[MGLMultiPoint class]]) {
- CLLocationCoordinate2D origin = annotation.coordinate;
+ CLLocationCoordinate2D origin = coordinate;
CGPoint originPoint = [self convertCoordinate:origin toPointToView:self];
return CGRectMake(originPoint.x, originPoint.y, MGLAnnotationImagePaddingForHitTest, MGLAnnotationImagePaddingForHitTest);
}
@@ -4626,7 +4654,7 @@ public:
return CGRectZero;
}
- CGRect positioningRect = [self frameOfImage:image centeredAtCoordinate:annotation.coordinate];
+ CGRect positioningRect = [self frameOfImage:image centeredAtCoordinate:coordinate];
positioningRect.origin.x -= 0.5;
return CGRectInset(positioningRect, -MGLAnnotationImagePaddingForCallout,
@@ -4680,6 +4708,7 @@ public:
// clean up
self.calloutViewForSelectedAnnotation = nil;
self.selectedAnnotation = nil;
+ self.anchorCoordinateForSelectedAnnotation = kCLLocationCoordinate2DInvalid;
// notify delegate
if ([self.delegate respondsToSelector:@selector(mapView:didDeselectAnnotation:)])
@@ -5889,6 +5918,7 @@ public:
- (void)updateCalloutView
{
+ // If we're moving the annotation and callout, don't update
UIView <MGLCalloutView> *calloutView = self.calloutViewForSelectedAnnotation;
id <MGLAnnotation> annotation = calloutView.representedObject;
@@ -6014,6 +6044,7 @@ public:
/// Intended center point of the user location annotation view with respect to
/// the overall map view (but respecting the content inset).
+
- (CGPoint)userLocationAnnotationViewCenter
{
if ([self.delegate respondsToSelector:@selector(mapViewUserLocationAnchorPoint:)])
diff --git a/platform/ios/vendor/SMCalloutView/SMCalloutView.m b/platform/ios/vendor/SMCalloutView/SMCalloutView.m
index 7f987c3355..66a7b5a7a7 100755
--- a/platform/ios/vendor/SMCalloutView/SMCalloutView.m
+++ b/platform/ios/vendor/SMCalloutView/SMCalloutView.m
@@ -269,6 +269,8 @@ NSTimeInterval const kMGLSMCalloutViewRepositionDelayForUIScrollView = 1.0/3.0;
- (UIEdgeInsets)marginInsetsHintForPresentationFromRect:(CGRect)rect {
+ const CGFloat defaultMargin = 20.0f;
+
// form our subviews based on our content set so far
[self rebuildSubviews];
@@ -281,16 +283,16 @@ NSTimeInterval const kMGLSMCalloutViewRepositionDelayForUIScrollView = 1.0/3.0;
CGFloat horizontalMargin = fmaxf(0, ceilf((CALLOUT_MIN_WIDTH-rect.size.width)/2));
UIEdgeInsets insets = {
- .top = 0.0f,
- .right = -horizontalMargin,
+ .top = 0.0f,
+ .right = -defaultMargin - horizontalMargin,
.bottom = 0.0f,
- .left = -horizontalMargin
+ .left = -defaultMargin - horizontalMargin
};
if (self.permittedArrowDirection == MGLSMCalloutArrowDirectionUp)
- insets.bottom -= size.height;
+ insets.bottom -= (defaultMargin + size.height);
else
- insets.top -= size.height;
+ insets.top -= (defaultMargin + size.height);
return insets;
}