From 1a88c0d17d6e8a7065ee164678b4dfcf4ad823b2 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Thu, 25 Aug 2016 13:09:56 -0700 Subject: [ios] Add annotation count feature to iosapp This adds a new option to add and then count two annotation features. --- platform/ios/app/MBXViewController.m | 70 ++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 3bf8cf257d..ba271cb850 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -44,6 +44,10 @@ static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXVie @property (nonatomic) NSInteger styleIndex; @property (nonatomic) BOOL debugLoggingEnabled; @property (nonatomic) BOOL customUserLocationAnnnotationEnabled; +@property (nonatomic) BOOL isTestingFeaturesInBox; +@property (nonatomic) UIView *featuresInBoxView; +@property (nonatomic) CLLocationCoordinate2D countPointCoordinate; +@property (nonatomic) UILabel *countLabel; @end @@ -208,6 +212,7 @@ static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXVie ? @"Disable Custom User Dot" : @"Enable Custom User Dot"), @"Query Annotations", + @"Count Features in Box", nil]; if (self.debugLoggingEnabled) @@ -299,6 +304,10 @@ static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXVie { [self testQueryPointAnnotations]; } + else if (buttonIndex == actionSheet.firstOtherButtonIndex + 19) + { + [self testCountFeaturesInBox]; + } else if (buttonIndex == actionSheet.numberOfButtons - 2 && self.debugLoggingEnabled) { NSString *fileContents = [NSString stringWithContentsOfFile:[self telemetryDebugLogfilePath] encoding:NSUTF8StringEncoding error:nil]; @@ -561,6 +570,39 @@ static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXVie [self presentViewController:alertController animated:YES completion:nil]; } +- (void)testCountFeaturesInBox { + self.isTestingFeaturesInBox = YES; + + // disable user dot + self.mapView.showsUserLocation = NO; + /// zoom in + [self.mapView setZoomLevel:15]; + + // visualize the target area + if (!self.featuresInBoxView) { + self.featuresInBoxView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMidX(self.view.bounds)-50, CGRectGetMidY(self.view.bounds)-50, 100, 100)]; + self.featuresInBoxView.backgroundColor = [UIColor grayColor]; + self.featuresInBoxView.alpha = 0.5; + [self.view addSubview:self.featuresInBoxView]; + } + + // add some target features + MGLPointAnnotation *pointAnnotation = [[MGLPointAnnotation alloc] init]; + CLLocationCoordinate2D pointCoordinate = self.mapView.centerCoordinate; + pointCoordinate.latitude += 0.004; + pointAnnotation.coordinate = pointCoordinate; + [self.mapView addAnnotation:pointAnnotation]; + + CLLocationCoordinate2D polygonStartingCoordinate = self.mapView.centerCoordinate; + polygonStartingCoordinate.latitude -= 0.001; + CLLocationCoordinate2D coords[2] = { + polygonStartingCoordinate, + CLLocationCoordinate2DMake(polygonStartingCoordinate.latitude - 15.001, polygonStartingCoordinate.longitude - 15.001) + }; + MGLPolyline *polyline = [MGLPolyline polylineWithCoordinates:coords count:2]; + [self.mapView addAnnotation:polyline]; +} + - (IBAction)handleLongPress:(UILongPressGestureRecognizer *)longPress { if (longPress.state == UIGestureRecognizerStateBegan) @@ -925,4 +967,32 @@ static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXVie point.coordinate = [self.mapView convertPoint:self.mapView.center toCoordinateFromView:self.mapView]; } +- (void)mapView:(MGLMapView *)mapView regionDidChangeAnimated:(BOOL)animated { + if (self.isTestingFeaturesInBox) { + + + if (!self.countLabel) { + self.countLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 21)]; + self.countLabel.center = CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetHeight(self.view.bounds) - 100); + self.countLabel.textAlignment = NSTextAlignmentCenter; + self.countLabel.backgroundColor = [UIColor whiteColor]; + [self.view addSubview:self.countLabel]; + } + + NSArray *features = [self.mapView visibleFeaturesInRect:self.featuresInBoxView.frame]; + BOOL foundPoint = NO; + BOOL foundLine = NO; + for (id feature in features) { + if ([feature isMemberOfClass:[MGLPolylineFeature class]] && feature.attributes.count == 0) { + foundLine = YES; + } + if ([feature isMemberOfClass:[MGLPointFeature class]] && feature.attributes.count == 0) { + foundPoint = YES; + } + } + + self.countLabel.text = [NSString stringWithFormat:@"point: %@, line: %@", @(foundPoint), @(foundLine)]; + } +} + @end -- cgit v1.2.1