[ios, macos] Hardened std::map usage in MGLMapVIew

Replaced std::map::operator[] usage with std::map::at(). Backed up an assertion on iOS with a guard when -annotationTagsInRect: returns the tag of a nonexistent annotation, for consistency with macOS. Removed an unnecessary and risky subscript into _annotationContextsByAnnotationTag in -positioningRectForCalloutForAnnotationWithTag: on iOS.
This commit is contained in:
Minh Nguyễn
2017-04-04 21:08:50 -07:00
committed by Minh Nguyễn
parent 5bfbe9603b
commit d39ea23b09
2 changed files with 9 additions and 7 deletions

View File

@@ -1820,7 +1820,7 @@ public:
return nil;
}
MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag[tag];
MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(tag);
return annotationContext.annotation;
}
@@ -2057,8 +2057,8 @@ public:
// Filter out any annotation whose image is unselectable or for which
// hit testing fails.
auto end = std::remove_if(nearbyAnnotations.begin(), nearbyAnnotations.end(), [&](const MGLAnnotationTag annotationTag) {
NSAssert(_annotationContextsByAnnotationTag.count(annotationTag) != 0, @"Unknown annotation found nearby click");
id <MGLAnnotation> annotation = [self annotationWithTag:annotationTag];
NSAssert(annotation, @"Unknown annotation found nearby click");
if (!annotation) {
return true;
}