summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2017-09-11 01:32:54 -0700
committerMinh Nguyễn <mxn@1ec5.org>2017-11-02 15:19:54 -0700
commit04ba3e2de2f983629e84d5b2a05c942166eefb33 (patch)
tree7568aeab23f4184930280bc1215c502ffe971fdb
parent0cf4b96bab568203fee54fb08ae520d7d2ce4ad4 (diff)
downloadqtlocation-mapboxgl-04ba3e2de2f983629e84d5b2a05c942166eefb33.tar.gz
[ios] Consistently sort accessibility elements
Also fixed an issue causing road feature accessibility elements to get treated like place feature accessibility elements.
-rw-r--r--platform/ios/src/MGLMapView.mm42
1 files changed, 34 insertions, 8 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 5b6b2612ff..cadfd74b6e 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -2573,7 +2573,7 @@ public:
}
MGLFeatureAccessibilityElement *element = [_featureAccessibilityElements objectsPassingTest:^BOOL(MGLFeatureAccessibilityElement * _Nonnull element, BOOL * _Nonnull stop) {
- return (element.feature.identifier && [element.feature.identifier isEqual:feature.identifier]) || [element.feature isEqual:feature];
+ return element.feature.identifier && ![element.feature.identifier isEqual:@0] && [element.feature.identifier isEqual:feature.identifier];
}].anyObject;
if (!element)
{
@@ -2602,7 +2602,7 @@ public:
}
MGLFeatureAccessibilityElement *element = [_featureAccessibilityElements objectsPassingTest:^BOOL(MGLFeatureAccessibilityElement * _Nonnull element, BOOL * _Nonnull stop) {
- return (element.feature.identifier && [element.feature.identifier isEqual:feature.identifier]) || [element.feature isEqual:feature];
+ return element.feature.identifier && ![element.feature.identifier isEqual:@0] && [element.feature.identifier isEqual:feature.identifier];
}].anyObject;
if (!element)
{
@@ -2709,6 +2709,16 @@ public:
if (tag != MGLAnnotationTagNotFound)
{
std::sort(visibleAnnotations.begin(), visibleAnnotations.end());
+ std::sort(visibleAnnotations.begin(), visibleAnnotations.end(), [&](const MGLAnnotationTag tagA, const MGLAnnotationTag tagB) {
+ CLLocationCoordinate2D coordinateA = [[self annotationWithTag:tagA] coordinate];
+ CLLocationCoordinate2D coordinateB = [[self annotationWithTag:tagB] coordinate];
+ CGPoint pointA = [self convertCoordinate:coordinateA toPointToView:self];
+ CGPoint pointB = [self convertCoordinate:coordinateB toPointToView:self];
+ CGFloat deltaA = hypot(pointA.x - centerPoint.x, pointA.y - centerPoint.y);
+ CGFloat deltaB = hypot(pointB.x - centerPoint.x, pointB.y - centerPoint.y);
+ return deltaA < deltaB;
+ });
+
auto foundElement = std::find(visibleAnnotations.begin(), visibleAnnotations.end(), tag);
if (foundElement == visibleAnnotations.end())
{
@@ -2720,14 +2730,22 @@ public:
// Visible place features
NSArray *visiblePlaceFeatures = self.visiblePlaceFeatures;
NSRange visiblePlaceFeatureRange = NSMakeRange(NSMaxRange(visibleAnnotationRange), visiblePlaceFeatures.count);
- if ([element isKindOfClass:[MGLFeatureAccessibilityElement class]])
+ if ([element isKindOfClass:[MGLPlaceFeatureAccessibilityElement class]])
{
- id <MGLFeature> feature = [(MGLFeatureAccessibilityElement *)element feature];
+ visiblePlaceFeatures = [visiblePlaceFeatures sortedArrayUsingComparator:^NSComparisonResult(id <MGLFeature> _Nonnull featureA, id <MGLFeature> _Nonnull featureB) {
+ CGPoint pointA = [self convertCoordinate:featureA.coordinate toPointToView:self];
+ CGPoint pointB = [self convertCoordinate:featureB.coordinate toPointToView:self];
+ CGFloat deltaA = hypot(pointA.x - centerPoint.x, pointA.y - centerPoint.y);
+ CGFloat deltaB = hypot(pointB.x - centerPoint.x, pointB.y - centerPoint.y);
+ return [@(deltaA) compare:@(deltaB)];
+ }];
+
+ id <MGLFeature> feature = [(MGLPlaceFeatureAccessibilityElement *)element feature];
NSUInteger featureIndex = [visiblePlaceFeatures indexOfObject:feature];
if (featureIndex == NSNotFound)
{
featureIndex = [visiblePlaceFeatures indexOfObjectPassingTest:^BOOL (id <MGLFeature> _Nonnull visibleFeature, NSUInteger idx, BOOL * _Nonnull stop) {
- return visibleFeature.identifier && [visibleFeature.identifier isEqual:feature.identifier];
+ return visibleFeature.identifier && ![visibleFeature.identifier isEqual:@0] && [visibleFeature.identifier isEqual:feature.identifier];
}];
}
if (featureIndex == NSNotFound)
@@ -2740,14 +2758,22 @@ public:
// Visible road features
NSArray *visibleRoadFeatures = self.visibleRoadFeatures;
NSRange visibleRoadFeatureRange = NSMakeRange(NSMaxRange(visiblePlaceFeatureRange), visibleRoadFeatures.count);
- if ([element isKindOfClass:[MGLFeatureAccessibilityElement class]])
+ if ([element isKindOfClass:[MGLRoadFeatureAccessibilityElement class]])
{
- id <MGLFeature> feature = [(MGLFeatureAccessibilityElement *)element feature];
+ visibleRoadFeatures = [visibleRoadFeatures sortedArrayUsingComparator:^NSComparisonResult(id <MGLFeature> _Nonnull featureA, id <MGLFeature> _Nonnull featureB) {
+ CGPoint pointA = [self convertCoordinate:featureA.coordinate toPointToView:self];
+ CGPoint pointB = [self convertCoordinate:featureB.coordinate toPointToView:self];
+ CGFloat deltaA = hypot(pointA.x - centerPoint.x, pointA.y - centerPoint.y);
+ CGFloat deltaB = hypot(pointB.x - centerPoint.x, pointB.y - centerPoint.y);
+ return [@(deltaA) compare:@(deltaB)];
+ }];
+
+ id <MGLFeature> feature = [(MGLRoadFeatureAccessibilityElement *)element feature];
NSUInteger featureIndex = [visibleRoadFeatures indexOfObject:feature];
if (featureIndex == NSNotFound)
{
featureIndex = [visibleRoadFeatures indexOfObjectPassingTest:^BOOL (id <MGLFeature> _Nonnull visibleFeature, NSUInteger idx, BOOL * _Nonnull stop) {
- return visibleFeature.identifier && [visibleFeature.identifier isEqual:feature.identifier];
+ return visibleFeature.identifier && ![visibleFeature.identifier isEqual:@0] && [visibleFeature.identifier isEqual:feature.identifier];
}];
}
if (featureIndex == NSNotFound)