summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Bounds <jesse@rebounds.net>2016-08-25 13:09:56 -0700
committerIvo van Dongen <info@ivovandongen.nl>2016-08-26 10:32:02 +0200
commit1a88c0d17d6e8a7065ee164678b4dfcf4ad823b2 (patch)
tree9b29063a2f145d54b020fce2f06e168c7faffc1c
parent06d8b41fc8d09de52a849086c6fb65082d085ef2 (diff)
downloadqtlocation-mapboxgl-1a88c0d17d6e8a7065ee164678b4dfcf4ad823b2.tar.gz
[ios] Add annotation count feature to iosapp
This adds a new option to add and then count two annotation features.
-rw-r--r--platform/ios/app/MBXViewController.m70
1 files changed, 70 insertions, 0 deletions
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<MGLFeature> 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