aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2018-10-06 00:48:02 -0400
committerJulian Rex <julian.rex@mapbox.com>2018-10-06 00:58:40 -0400
commita1cb3c7003341386252ef86ff0deec427ed1084d (patch)
treebcfb1896b5044fc6fecd4ddbf8a9f61984d684ca
parent10ca63bae419016c5406e2516ea15713c20ba8a6 (diff)
[macos] Updated to use new delegate method. Fixed bug with bring-in-view code.
-rw-r--r--platform/macos/src/MGLMapView.mm76
-rw-r--r--platform/macos/src/MGLMapViewDelegate.h16
2 files changed, 62 insertions, 30 deletions
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index 919c6d1fb..b1fac32a1 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -1518,7 +1518,14 @@ public:
if (hitAnnotationTag != _selectedAnnotationTag) {
id <MGLAnnotation> annotation = [self annotationWithTag:hitAnnotationTag];
NSAssert(annotation, @"Cannot select nonexistent annotation with tag %u", hitAnnotationTag);
- [self selectAnnotation:annotation atPoint:gesturePoint];
+
+ BOOL expose = YES;
+
+ if ([self.delegate respondsToSelector:@selector(mapView:shouldExposeAnnotationInResponseToUserSelection:)]) {
+ expose = [self.delegate mapView:self shouldExposeAnnotationInResponseToUserSelection:annotation];
+ }
+
+ [self selectAnnotation:annotation atPoint:gesturePoint animated:YES expose:expose];
}
} else {
[self deselectAnnotation:self.selectedAnnotation];
@@ -2254,10 +2261,15 @@ public:
- (void)selectAnnotation:(id <MGLAnnotation>)annotation atPoint:(NSPoint)gesturePoint
{
- [self selectAnnotation:annotation atPoint:gesturePoint moveOnscreen:YES animateSelection:YES];
+ [self selectAnnotation:annotation atPoint:gesturePoint animated:YES];
}
-- (void)selectAnnotation:(id <MGLAnnotation>)annotation atPoint:(NSPoint)gesturePoint moveOnscreen:(BOOL)moveOnscreen animateSelection:(BOOL)animateSelection
+- (void)selectAnnotation:(id <MGLAnnotation>)annotation atPoint:(NSPoint)gesturePoint animated:(BOOL)animated
+{
+ [self selectAnnotation:annotation atPoint:gesturePoint animated:animated expose:animated];
+}
+
+- (void)selectAnnotation:(id <MGLAnnotation>)annotation atPoint:(NSPoint)gesturePoint animated:(BOOL)animated expose:(BOOL)expose
{
id <MGLAnnotation> selectedAnnotation = self.selectedAnnotation;
if (annotation == selectedAnnotation) {
@@ -2273,10 +2285,6 @@ public:
[self addAnnotation:annotation];
}
- if (moveOnscreen) {
- moveOnscreen = [self isBringingAnnotationOnscreenSupportedForAnnotation:annotation animated:animateSelection];
- }
-
// The annotation's anchor will bounce to the current click.
NSRect positioningRect = [self positioningRectForCalloutForAnnotationWithTag:annotationTag];
@@ -2286,7 +2294,7 @@ public:
positioningRect.origin = [self convertCoordinate:origin toPointToView:self];
}
- if (!moveOnscreen && NSIsEmptyRect(NSIntersectionRect(positioningRect, self.bounds))) {
+ if (!expose && NSIsEmptyRect(NSIntersectionRect(positioningRect, self.bounds))) {
if (!NSEqualPoints(gesturePoint, NSZeroPoint)) {
positioningRect = CGRectMake(gesturePoint.x, gesturePoint.y, positioningRect.size.width, positioningRect.size.height);
}
@@ -2319,13 +2327,13 @@ public:
[callout showRelativeToRect:positioningRect ofView:self preferredEdge:edge];
}
- if (moveOnscreen)
+ if (expose)
{
- moveOnscreen = NO;
+ expose = NO;
NSRect (^edgeInsetsInsetRect)(NSRect, NSEdgeInsets) = ^(NSRect rect, NSEdgeInsets insets) {
return NSMakeRect(rect.origin.x + insets.left,
- rect.origin.y + insets.top,
+ rect.origin.y + insets.bottom,
rect.size.width - insets.left - insets.right,
rect.size.height - insets.top - insets.bottom);
};
@@ -2338,33 +2346,41 @@ public:
CGRect bounds = constrainedRect;
// Any one of these cases should trigger a move onscreen
- if (CGRectGetMinX(positioningRect) < CGRectGetMinX(bounds))
- {
- constrainedRect.origin.x = expandedPositioningRect.origin.x;
- moveOnscreen = YES;
+ CGFloat minX = CGRectGetMinX(expandedPositioningRect);
+
+ if (minX < CGRectGetMinX(bounds)) {
+ constrainedRect.origin.x = minX;
+ expose = YES;
}
- else if (CGRectGetMaxX(positioningRect) > CGRectGetMaxX(bounds))
- {
- constrainedRect.origin.x = CGRectGetMaxX(expandedPositioningRect) - constrainedRect.size.width;
- moveOnscreen = YES;
+ else {
+ CGFloat maxX = CGRectGetMaxX(expandedPositioningRect);
+
+ if (maxX > CGRectGetMaxX(bounds)) {
+ constrainedRect.origin.x = maxX - CGRectGetWidth(constrainedRect);
+ expose = YES;
+ }
}
-
- if (CGRectGetMinY(positioningRect) < CGRectGetMinY(bounds))
- {
- constrainedRect.origin.y = expandedPositioningRect.origin.y;
- moveOnscreen = YES;
+
+ CGFloat minY = CGRectGetMinY(expandedPositioningRect);
+
+ if (minY < CGRectGetMinY(bounds)) {
+ constrainedRect.origin.y = minY;
+ expose = YES;
}
- else if (CGRectGetMaxY(positioningRect) > CGRectGetMaxY(bounds))
- {
- constrainedRect.origin.y = CGRectGetMaxY(expandedPositioningRect) - constrainedRect.size.height;
- moveOnscreen = YES;
+ else {
+ CGFloat maxY = CGRectGetMaxY(expandedPositioningRect);
+
+ if (maxY > CGRectGetMaxY(bounds)) {
+ constrainedRect.origin.y = maxY - CGRectGetHeight(constrainedRect);
+ expose = YES;
+ }
}
- if (moveOnscreen)
+ if (expose)
{
CGPoint center = CGPointMake(CGRectGetMidX(constrainedRect), CGRectGetMidY(constrainedRect));
CLLocationCoordinate2D centerCoord = [self convertPoint:center toCoordinateFromView:self];
- [self setCenterCoordinate:centerCoord animated:animateSelection];
+ [self setCenterCoordinate:centerCoord animated:animated];
}
}
}
diff --git a/platform/macos/src/MGLMapViewDelegate.h b/platform/macos/src/MGLMapViewDelegate.h
index 2a8b28c1b..5abd025a5 100644
--- a/platform/macos/src/MGLMapViewDelegate.h
+++ b/platform/macos/src/MGLMapViewDelegate.h
@@ -256,6 +256,22 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)mapView:(MGLMapView *)mapView shapeAnnotationIsEnabled:(MGLShape *)annotation;
/**
+ Returns a Boolean value indicating whether the annotation should be brought into view
+ in response to selection by clicking.
+
+ If the delegate does not implement this method, the default value is `YES`.
+
+ Note that user-initiated selections are always animated.
+
+ @param mapView The map view that has selected the annotation.
+ @param annotation The object representing the shape annotation.
+ @return A Boolean value indicating whether the annotation should be moved into view. This value
+ can be considered to be the same as the `expose` parameter passed to `-[MGLMapView selectAnnotation:animated:expose:]`
+ */
+- (BOOL)mapView:(MGLMapView *)mapView shouldExposeAnnotationInResponseToUserSelection:(id <MGLAnnotation>)annotation;
+
+
+/**
Tells the delegate that one of its annotations has been selected.
You can use this method to track changes to the selection state of annotations.