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

Commit

Permalink
Restored compass and ℹ️ accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed May 12, 2015
1 parent 2e71630 commit 058bad8
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1443,13 +1443,30 @@ - (CGRect)accessibilityFrame
- (NSInteger)accessibilityElementCount
{
std::vector<MGLAnnotationID> visibleAnnotations = _mbglMap->getAnnotationsInBounds(self.viewportBounds);
return visibleAnnotations.size();
NSInteger count = visibleAnnotations.size();
return count + 2 /* compass, attributionButton */;
}

- (id)accessibilityElementAtIndex:(NSInteger)index
{
MGLAnnotationID annotationID = [self visibleAnnotationIDAtIndex:index];
NSAssert(annotationID != MGLAnnotationNotFound, @"No visible annotation at index %li", index);
std::vector<MGLAnnotationID> visibleAnnotations = _mbglMap->getAnnotationsInBounds(self.viewportBounds);

// Ornaments
if (index == 0)
{
return self.compass;
}
if (index > 0 && (NSUInteger)index == visibleAnnotations.size() + 1 /* compass */)
{
return self.attributionButton;
}

// Annotations
std::sort(visibleAnnotations.begin(), visibleAnnotations.end());
NSInteger annotationIndex = index - 1 /* compass */;
MGLAnnotationID annotationID = visibleAnnotations[annotationIndex];
NSAssert(annotationID != MGLAnnotationNotFound,
@"No visible annotation at index %li", annotationIndex);
auto &annotationContext = _annotationContextsByAnnotationID[annotationID];
NSAssert(annotationContext.count(MGLAnnotationContextAnnotationKey),
@"Missing annotation for ID %u", annotationID);
Expand Down Expand Up @@ -1486,26 +1503,28 @@ - (id)accessibilityElementAtIndex:(NSInteger)index
return element;
}

- (MGLAnnotationID)visibleAnnotationIDAtIndex:(NSInteger)index
{
std::vector<MGLAnnotationID> visibleAnnotations = _mbglMap->getAnnotationsInBounds(self.viewportBounds);
std::sort(visibleAnnotations.begin(), visibleAnnotations.end());
return visibleAnnotations[index];
}

- (NSInteger)indexOfAccessibilityElement:(id)element
{
if (![element isKindOfClass:[MGLAnnotationAccessibilityElement class]])
if (element == self.compass)
{
return 0;
}
if ( ! [element isKindOfClass:[MGLAnnotationAccessibilityElement class]] &&
element != self.attributionButton)
{
return NSNotFound;
}

std::vector<MGLAnnotationID> visibleAnnotations = _mbglMap->getAnnotationsInBounds(self.viewportBounds);
if (element == self.attributionButton)
{
return visibleAnnotations.size();
}
std::sort(visibleAnnotations.begin(), visibleAnnotations.end());
auto foundElement = std::find(visibleAnnotations.begin(), visibleAnnotations.end(),
((MGLAnnotationAccessibilityElement *)element).identifier);
if (foundElement == visibleAnnotations.end()) return NSNotFound;
else return std::distance(visibleAnnotations.begin(), foundElement);
else return std::distance(visibleAnnotations.begin(), foundElement) + 1;
}

#pragma mark - Geography -
Expand Down

0 comments on commit 058bad8

Please sign in to comment.