fixes #2611: iOS test app long press drops debug marker

This commit is contained in:
Justin R. Miller
2015-10-13 17:53:13 -07:00
parent 074d61a55e
commit 6e1b1836f4
2 changed files with 58 additions and 0 deletions

View File

@@ -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];

View File

@@ -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;