Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[macos] Add visible annotations API
Browse files Browse the repository at this point in the history
  • Loading branch information
boundsj committed Oct 26, 2016
1 parent 60889d4 commit 9ed7757
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion platform/ios/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ IB_DESIGNABLE

/**
The complete list of annotations associated with the receiver that are
currently visible. (read-only)
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
Expand Down
10 changes: 10 additions & 0 deletions platform/macos/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,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.
Expand Down
24 changes: 24 additions & 0 deletions platform/macos/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,30 @@ - (IBAction)rotate:(NSSlider *)sender {
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 {
if (!_annotationContextsByAnnotationTag.count(tag)) {
Expand Down

0 comments on commit 9ed7757

Please sign in to comment.