diff options
-rw-r--r-- | platform/ios/src/MGLAnnotationView.mm | 7 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 1 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView_Internal.h | 3 | ||||
-rw-r--r-- | platform/ios/test/MGLAnnotationViewTests.m | 38 |
4 files changed, 42 insertions, 7 deletions
diff --git a/platform/ios/src/MGLAnnotationView.mm b/platform/ios/src/MGLAnnotationView.mm index e086e3bde5..7068cdc0db 100644 --- a/platform/ios/src/MGLAnnotationView.mm +++ b/platform/ios/src/MGLAnnotationView.mm @@ -187,7 +187,7 @@ { CGPoint center = [sender locationInView:sender.view.superview]; [self setCenter:center pitch:self.mapView.camera.pitch]; - + if (sender.state == UIGestureRecognizerStateEnded) { self.dragState = MGLAnnotationViewDragStateNone; } @@ -206,9 +206,10 @@ if (dragState == MGLAnnotationViewDragStateStarting) { + [self.mapView.calloutViewForSelectedAnnotation dismissCalloutAnimated:animated]; [self.superview bringSubviewToFront:self]; } - + if (dragState == MGLAnnotationViewDragStateEnding) { if ([self.mapView.delegate respondsToSelector:@selector(mapView:didDragAnnotationView:toCoordinate:)]) @@ -231,7 +232,7 @@ { return NO; } - + return YES; } diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 25cf23c878..cd41f41d21 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -3004,6 +3004,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) if (annotationView) { annotationView.annotation = annotation; + annotationView.mapView = self; CGRect bounds = UIEdgeInsetsInsetRect({ CGPointZero, annotationView.frame.size }, annotationView.alignmentRectInsets); _largestAnnotationViewSize = CGSizeMake(MAX(_largestAnnotationViewSize.width, CGRectGetWidth(bounds)), diff --git a/platform/ios/src/MGLMapView_Internal.h b/platform/ios/src/MGLMapView_Internal.h index 6225e11749..9133aca857 100644 --- a/platform/ios/src/MGLMapView_Internal.h +++ b/platform/ios/src/MGLMapView_Internal.h @@ -5,6 +5,9 @@ extern const CGSize MGLAnnotationAccessibilityElementMinimumSize; @interface MGLMapView (Internal) +/// Currently shown popover representing the selected annotation. +@property (nonatomic) UIView<MGLCalloutView> *calloutViewForSelectedAnnotation; + /** Triggers another render pass even when it is not necessary. */ - (void)setNeedsGLDisplay; diff --git a/platform/ios/test/MGLAnnotationViewTests.m b/platform/ios/test/MGLAnnotationViewTests.m index 541c43b5a1..6cc5698393 100644 --- a/platform/ios/test/MGLAnnotationViewTests.m +++ b/platform/ios/test/MGLAnnotationViewTests.m @@ -3,6 +3,17 @@ static NSString * const MGLTestAnnotationReuseIdentifer = @"MGLTestAnnotationReuseIdentifer"; +@interface MGLAnnotationView (Test) +@property (nonatomic) MGLMapView *mapView; +@property (nonatomic, readwrite) MGLAnnotationViewDragState dragState; + +- (void)setDragState:(MGLAnnotationViewDragState)dragState; +@end + +@interface MGLMapView (Test) +@property (nonatomic) UIView<MGLCalloutView> *calloutViewForSelectedAnnotation; +@end + @interface MGLTestAnnotation : NSObject <MGLAnnotation> @property (nonatomic, assign) CLLocationCoordinate2D coordinate; @end @@ -10,6 +21,19 @@ static NSString * const MGLTestAnnotationReuseIdentifer = @"MGLTestAnnotationReu @implementation MGLTestAnnotation @end +@interface MGLTestCalloutView: UIView<MGLCalloutView> +@property (nonatomic) BOOL didCallDismissCalloutAnimated; +@end + +@implementation MGLTestCalloutView + +- (void)dismissCalloutAnimated:(BOOL)animated +{ + _didCallDismissCalloutAnimated = YES; +} + +@end + @interface MGLAnnotationViewTests : XCTestCase <MGLMapViewDelegate> @property (nonatomic) XCTestExpectation *expectation; @property (nonatomic) MGLMapView *mapView; @@ -28,15 +52,21 @@ static NSString * const MGLTestAnnotationReuseIdentifer = @"MGLTestAnnotationReu - (void)testAnnotationView { _expectation = [self expectationWithDescription:@"annotation property"]; - + MGLTestAnnotation *annotation = [[MGLTestAnnotation alloc] init]; [_mapView addAnnotation:annotation]; - + [self waitForExpectationsWithTimeout:1 handler:nil]; - + XCTAssert(_mapView.annotations.count == 1, @"number of annotations should be 1"); XCTAssertNotNil(_annotationView.annotation, @"annotation property should not be nil"); - + XCTAssertNotNil(_annotationView.mapView, @"mapView property should not be nil"); + + MGLTestCalloutView *testCalloutView = [[MGLTestCalloutView alloc] init]; + _mapView.calloutViewForSelectedAnnotation = testCalloutView; + _annotationView.dragState = MGLAnnotationViewDragStateStarting; + XCTAssertTrue(testCalloutView.didCallDismissCalloutAnimated, @"callout view was not dismissed"); + [_mapView removeAnnotation:_annotationView.annotation]; XCTAssert(_mapView.annotations.count == 0, @"number of annotations should be 0"); |