diff options
author | Jesse Bounds <jesse@rebounds.net> | 2016-10-26 17:13:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-26 17:13:38 -0700 |
commit | d5af9b680b6b72eea7cd149a4552bd20bb676353 (patch) | |
tree | 84dc9c367ab616edd1219fe237034a5b2f524095 /platform/macos | |
parent | 67ffc9685e573b10e4761b0bdb9962c79139f5da (diff) | |
download | qtlocation-mapboxgl-d5af9b680b6b72eea7cd149a4552bd20bb676353.tar.gz |
[ios, macos] Introduce visible annotations API (#6061)
Add visibleAnnotations API to make it easier for clients of MGLMapView
to query for all visible annotations in the map or all visible annotations
in a subsection of the map.
Diffstat (limited to 'platform/macos')
-rw-r--r-- | platform/macos/src/MGLMapView.h | 21 | ||||
-rw-r--r-- | platform/macos/src/MGLMapView.mm | 29 |
2 files changed, 50 insertions, 0 deletions
diff --git a/platform/macos/src/MGLMapView.h b/platform/macos/src/MGLMapView.h index 3499671ff1..3dbbbe3d82 100644 --- a/platform/macos/src/MGLMapView.h +++ b/platform/macos/src/MGLMapView.h @@ -569,6 +569,16 @@ IB_DESIGNABLE - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations; /** + The complete list of annotations associated with the receiver that are + currently visible. + + 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; + +/** Removes an annotation from the map view, deselecting it if it is selected. Removing an annotation object dissociates it from the map view entirely, @@ -608,6 +618,17 @@ IB_DESIGNABLE */ - (nullable MGLAnnotationImage *)dequeueReusableAnnotationImageWithIdentifier:(NSString *)identifier; +/** + Returns the list of annotations associated with the receiver that intersect with + the given rectangle. + + @param rect A rectangle expressed in the map view’s coordinate system. + @return An array of objects that adopt the `MGLAnnotation` protocol or `nil` if + no annotations associated with the map view are currently visible in the + rectangle. + */ +- (nullable NS_ARRAY_OF(id <MGLAnnotation>) *)visibleAnnotationsInRect:(CGRect)rect; + #pragma mark Managing Annotation Selections /** diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 14b83762a3..4d1f00359d 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -1616,6 +1616,35 @@ public: return [NSArray arrayWithObjects:&annotations[0] count:annotations.size()]; } +- (nullable NS_ARRAY_OF(id <MGLAnnotation>) *)visibleAnnotations +{ + return [self visibleFeaturesInRect:self.bounds]; +} + +- (nullable NS_ARRAY_OF(id <MGLAnnotation>) *)visibleAnnotationsInRect:(CGRect)rect +{ + if (_annotationContextsByAnnotationTag.empty()) + { + return nil; + } + + std::vector<MGLAnnotationTag> annotationTags = [self annotationTagsInRect:rect]; + 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 { if (!_annotationContextsByAnnotationTag.count(tag)) { |