summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/ios/app/MBXViewController.m19
-rw-r--r--platform/ios/src/MGLMapView.h10
-rw-r--r--platform/ios/src/MGLMapView.mm24
3 files changed, 53 insertions, 0 deletions
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index bd8230ea15..3bf8cf257d 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -207,6 +207,7 @@ static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXVie
((_customUserLocationAnnnotationEnabled)
? @"Disable Custom User Dot"
: @"Enable Custom User Dot"),
+ @"Query Annotations",
nil];
if (self.debugLoggingEnabled)
@@ -294,6 +295,10 @@ static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXVie
self.mapView.showsUserLocation = NO;
self.mapView.userTrackingMode = MGLUserTrackingModeFollow;
}
+ else if (buttonIndex == actionSheet.firstOtherButtonIndex + 18)
+ {
+ [self testQueryPointAnnotations];
+ }
else if (buttonIndex == actionSheet.numberOfButtons - 2 && self.debugLoggingEnabled)
{
NSString *fileContents = [NSString stringWithContentsOfFile:[self telemetryDebugLogfilePath] encoding:NSUTF8StringEncoding error:nil];
@@ -542,6 +547,20 @@ static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXVie
roadLayer.minimumZoomLevel = 13;
}
+- (void)testQueryPointAnnotations {
+ NSNumber *visibleAnnotationCount = @(self.mapView.visibleAnnotations.count);
+ NSString *message;
+ if ([visibleAnnotationCount integerValue] == 1) {
+ message = [NSString stringWithFormat:@"There is %@ visible annotation.", visibleAnnotationCount];
+ } else {
+ message = [NSString stringWithFormat:@"There are %@ visible annotations.", visibleAnnotationCount];
+ }
+
+ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Visible Annotations" message:message preferredStyle:UIAlertControllerStyleAlert];
+ [alertController addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleCancel handler:nil]];
+ [self presentViewController:alertController animated:YES completion:nil];
+}
+
- (IBAction)handleLongPress:(UILongPressGestureRecognizer *)longPress
{
if (longPress.state == UIGestureRecognizerStateBegan)
diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h
index 57b74daa04..837e87c95a 100644
--- a/platform/ios/src/MGLMapView.h
+++ b/platform/ios/src/MGLMapView.h
@@ -893,6 +893,16 @@ IB_DESIGNABLE
@property (nonatomic, readonly, nullable) NS_ARRAY_OF(id <MGLAnnotation>) *annotations;
/**
+ The complete list of annotations associated with the receiver that are
+ currently visible. (read-only)
+
+ The objects in this array must adopt the `MGLAnnotation` protocol. If no
+ annotations are associated with the map view or if no annotations associated
+ with the map view are currently visible, the value of this property is `nil`.
+ */
+@property (nonatomic, readonly, nullable) NS_ARRAY_OF(id <MGLAnnotation>) *visibleAnnotations;
+
+/**
Adds an annotation to the map view.
@note `MGLMultiPolyline`, `MGLMultiPolygon`, and `MGLShapeCollection` objects
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index c3091a588b..355c077cd0 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -2764,6 +2764,30 @@ public:
return [NSArray arrayWithObjects:&annotations[0] count:annotations.size()];
}
+- (nullable NS_ARRAY_OF(id <MGLAnnotation>) *)visibleAnnotations
+{
+ if (_annotationContextsByAnnotationTag.empty())
+ {
+ return nil;
+ }
+
+ std::vector<MGLAnnotationTag> annotationTags = [self annotationTagsInRect:self.bounds];
+ if (annotationTags.size())
+ {
+ NSMutableArray *annotations = [NSMutableArray arrayWithCapacity:annotationTags.size()];
+
+ for (auto const& annotationTag: annotationTags)
+ {
+ MGLAnnotationContext annotationContext = _annotationContextsByAnnotationTag[annotationTag];
+ [annotations addObject:annotationContext.annotation];
+ }
+
+ return [annotations copy];
+ }
+
+ return nil;
+}
+
/// Returns the annotation assigned the given tag. Cheap.
- (id <MGLAnnotation>)annotationWithTag:(MGLAnnotationTag)tag
{