summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin R. Miller <incanus@codesorcery.net>2015-10-13 17:53:13 -0700
committerJustin R. Miller <incanus@codesorcery.net>2015-10-15 11:33:58 -0700
commit6e1b1836f472dee2a57cf11766eb1a04a11ad40a (patch)
tree33057639d638c179960cc4b4e32e5e106facb819
parent074d61a55e32e83173ec12b2eb34b78ddaaf0ef1 (diff)
downloadqtlocation-mapboxgl-6e1b1836f472dee2a57cf11766eb1a04a11ad40a.tar.gz
fixes #2611: iOS test app long press drops debug marker
-rw-r--r--ios/app/MBXViewController.mm18
-rw-r--r--test/ios/MapViewTests.m40
2 files changed, 58 insertions, 0 deletions
diff --git a/ios/app/MBXViewController.mm b/ios/app/MBXViewController.mm
index d05d142a52..302efbe9fc 100644
--- a/ios/app/MBXViewController.mm
+++ b/ios/app/MBXViewController.mm
@@ -82,6 +82,8 @@ static NSUInteger const kStyleVersion = 8;
target:self
action:@selector(locateUser)];
+ [self.mapView addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]];
+
[self restoreState:nil];
}
@@ -296,6 +298,20 @@ static NSUInteger const kStyleVersion = 8;
});
}
+- (void)handleLongPress:(UILongPressGestureRecognizer *)longPress
+{
+ if (longPress.state == UIGestureRecognizerStateBegan)
+ {
+ MGLPointAnnotation *point = [MGLPointAnnotation new];
+ point.coordinate = [self.mapView convertPoint:[longPress locationInView:longPress.view]
+ toCoordinateFromView:self.mapView];
+ point.title = @"Dropped Marker";
+ point.subtitle = [NSString stringWithFormat:@"lat: %.3f, lon: %.3f", point.coordinate.latitude, point.coordinate.longitude];
+ [self.mapView addAnnotation:point];
+ [self.mapView selectAnnotation:point animated:YES];
+ }
+}
+
- (void)cycleStyles
{
UIButton *titleButton = (UIButton *)self.navigationItem.titleView;
@@ -354,6 +370,8 @@ static NSUInteger const kStyleVersion = 8;
- (MGLAnnotationImage *)mapView:(MGLMapView * __nonnull)mapView imageForAnnotation:(id <MGLAnnotation> __nonnull)annotation
{
+ if ([annotation.title isEqualToString:@"Dropped Marker"]) return nil; // use default marker
+
NSString *title = [(MGLPointAnnotation *)annotation title];
NSString *lastTwoCharacters = [title substringFromIndex:title.length - 2];
diff --git a/test/ios/MapViewTests.m b/test/ios/MapViewTests.m
index 1de31c6ccd..71e73054f4 100644
--- a/test/ios/MapViewTests.m
+++ b/test/ios/MapViewTests.m
@@ -33,6 +33,8 @@
tester.mapView.scrollEnabled = YES;
tester.mapView.rotateEnabled = YES;
+ [tester.mapView removeAnnotations:tester.mapView.annotations];
+
tester.viewController.navigationController.navigationBarHidden = YES;
tester.viewController.navigationController.toolbarHidden = YES;
@@ -331,6 +333,44 @@
@"setting zoom should take effect");
}
+- (void)testMarkerSelection {
+ CGPoint point = CGPointMake(100, 100);
+ MGLPointAnnotation *marker = [MGLPointAnnotation new];
+ marker.coordinate = [tester.mapView convertPoint:point toCoordinateFromView:tester.mapView];
+ marker.title = @"test"; // title required for callout
+ [tester.mapView addAnnotation:marker];
+
+ XCTAssertEqual(tester.mapView.selectedAnnotations.count, 0);
+
+ [tester.mapView selectAnnotation:marker animated:NO];
+ XCTAssertEqualObjects(tester.mapView.selectedAnnotations.firstObject, marker);
+
+ [tester.mapView deselectAnnotation:marker animated:NO];
+ XCTAssertEqual(tester.mapView.selectedAnnotations.count, 0);
+}
+
+- (void)testMarkerAddWithoutDelegate {
+ XCTAssertFalse([tester.viewController respondsToSelector:@selector(mapView:imageForAnnotation:)]);
+
+ MGLPointAnnotation *marker = [MGLPointAnnotation new];
+ marker.coordinate = tester.mapView.centerCoordinate;
+ [tester.mapView addAnnotation:marker];
+
+ [tester.mapView selectAnnotation:marker animated:NO];
+ XCTAssertEqualObjects(tester.mapView.selectedAnnotations.firstObject, marker);
+ XCTAssertEqual([[tester.mapView subviewsWithClassNamePrefix:@"SM"] count], 0); // no callout for no title
+
+ [tester.mapView deselectAnnotation:marker animated:NO];
+ marker.title = @"test";
+ [tester.mapView selectAnnotation:marker animated:NO];
+ XCTAssertEqualObjects(tester.mapView.selectedAnnotations.firstObject, marker);
+ XCTAssertGreaterThan([[tester.mapView subviewsWithClassNamePrefix:@"SM"] count], 0);
+}
+
+- (BOOL)mapView:(MGLMapView *)mapView annotationCanShowCallout:(id<MGLAnnotation>)annotation {
+ return YES;
+}
+
- (void)testTopLayoutGuide {
CGRect statusBarFrame, navigationBarFrame, compassFrame;
UINavigationBar *navigationBar = tester.viewController.navigationController.navigationBar;