summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Bounds <jesse@rebounds.net>2016-08-17 16:23:20 -0700
committerJesse Bounds <jesse@rebounds.net>2016-08-24 11:51:33 -0700
commit06d8b41fc8d09de52a849086c6fb65082d085ef2 (patch)
tree052549b2f6c8ef17926c3cbedb62020fdfed5dc0
parent2523f33ac440be1a817e50d2d8bdc4d9c5b0a9d9 (diff)
downloadqtlocation-mapboxgl-06d8b41fc8d09de52a849086c6fb65082d085ef2.tar.gz
[ios] Introduce visible annotations API
This adds an API for getting all annotations that are currently visible on the map. In the future, an additional API can be added to query by a specific rect. That API can be used internally to power this one. This also adds a new option to iosapp to test the feature. At the time of this commit, the underlying `queryPointAnnotations` does not appear to work as expected.
-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
{