summaryrefslogtreecommitdiff
path: root/platform/ios
diff options
context:
space:
mode:
authorFabian Guerra Soto <fabian.guerra@mapbox.com>2017-10-27 10:24:12 -0400
committerGitHub <noreply@github.com>2017-10-27 10:24:12 -0400
commit372698aa23d2fb371df6790aa96d83bdf735edc9 (patch)
tree9dc77d4aa9d8f16e9793541f354314f50bd61351 /platform/ios
parenta6140019657d88a966e362197118dc6c3e143fe0 (diff)
downloadqtlocation-mapboxgl-372698aa23d2fb371df6790aa96d83bdf735edc9.tar.gz
[ios, macos] Iterate over point and shape annotations. (#10262)
Diffstat (limited to 'platform/ios')
-rw-r--r--platform/ios/src/MGLMapView.mm90
1 files changed, 46 insertions, 44 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 740555840f..a7d2e17ce9 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -3776,11 +3776,10 @@ public:
queryRect = CGRectInset(queryRect, -MGLAnnotationImagePaddingForHitTest,
-MGLAnnotationImagePaddingForHitTest);
std::vector<MGLAnnotationTag> nearbyAnnotations = [self annotationTagsInRect:queryRect];
- BOOL queryingShapeAnnotations = NO;
+ std::vector<MGLAnnotationTag> nearbyShapeAnnotations = [self shapeAnnotationTagsInRect:queryRect];
- if (!nearbyAnnotations.size()) {
- nearbyAnnotations = [self shapeAnnotationTagsInRect:queryRect];
- queryingShapeAnnotations = YES;
+ if (nearbyShapeAnnotations.size()) {
+ nearbyAnnotations.insert(nearbyAnnotations.end(), nearbyShapeAnnotations.begin(), nearbyShapeAnnotations.end());
}
if (nearbyAnnotations.size())
@@ -3790,54 +3789,57 @@ public:
-MGLAnnotationImagePaddingForHitTest,
-MGLAnnotationImagePaddingForHitTest);
- if (!queryingShapeAnnotations) {
- // Filter out any annotation whose image or view is unselectable or for which
- // hit testing fails.
- auto end = std::remove_if(nearbyAnnotations.begin(), nearbyAnnotations.end(), [&](const MGLAnnotationTag annotationTag) {
- id <MGLAnnotation> annotation = [self annotationWithTag:annotationTag];
- NSAssert(annotation, @"Unknown annotation found nearby tap");
- if ( ! annotation)
+ // Filter out any annotation whose image or view is unselectable or for which
+ // hit testing fails.
+ auto end = std::remove_if(nearbyAnnotations.begin(), nearbyAnnotations.end(), [&](const MGLAnnotationTag annotationTag) {
+ id <MGLAnnotation> annotation = [self annotationWithTag:annotationTag];
+ NSAssert(annotation, @"Unknown annotation found nearby tap");
+ if ( ! annotation)
+ {
+ return true;
+ }
+
+ MGLAnnotationContext annotationContext = _annotationContextsByAnnotationTag.at(annotationTag);
+ CGRect annotationRect;
+
+ MGLAnnotationView *annotationView = annotationContext.annotationView;
+
+ if (annotationView)
+ {
+ if ( ! annotationView.enabled)
{
return true;
}
-
- MGLAnnotationContext annotationContext = _annotationContextsByAnnotationTag.at(annotationTag);
- CGRect annotationRect;
-
- MGLAnnotationView *annotationView = annotationContext.annotationView;
-
- if (annotationView)
+
+ CGPoint calloutAnchorPoint = MGLPointRounded([self convertCoordinate:annotation.coordinate toPointToView:self]);
+ CGRect frame = CGRectInset({ calloutAnchorPoint, CGSizeZero }, -CGRectGetWidth(annotationView.frame) / 2, -CGRectGetHeight(annotationView.frame) / 2);
+ annotationRect = UIEdgeInsetsInsetRect(frame, annotationView.alignmentRectInsets);
+ }
+ else
+ {
+ if ([annotation isKindOfClass:[MGLShape class]])
{
- if ( ! annotationView.enabled)
- {
- return true;
- }
-
- CGPoint calloutAnchorPoint = MGLPointRounded([self convertCoordinate:annotation.coordinate toPointToView:self]);
- CGRect frame = CGRectInset({ calloutAnchorPoint, CGSizeZero }, -CGRectGetWidth(annotationView.frame) / 2, -CGRectGetHeight(annotationView.frame) / 2);
- annotationRect = UIEdgeInsetsInsetRect(frame, annotationView.alignmentRectInsets);
+ return false;
}
- else
+
+ MGLAnnotationImage *annotationImage = [self imageOfAnnotationWithTag:annotationTag];
+ if ( ! annotationImage.enabled)
{
- MGLAnnotationImage *annotationImage = [self imageOfAnnotationWithTag:annotationTag];
- if ( ! annotationImage.enabled)
- {
- return true;
- }
-
- MGLAnnotationImage *fallbackAnnotationImage = [self dequeueReusableAnnotationImageWithIdentifier:MGLDefaultStyleMarkerSymbolName];
- UIImage *fallbackImage = fallbackAnnotationImage.image;
-
- annotationRect = [self frameOfImage:annotationImage.image ?: fallbackImage centeredAtCoordinate:annotation.coordinate];
+ return true;
}
-
- // Filter out the annotation if the fattened finger didn’t land
- // within the image’s alignment rect.
- return !!!CGRectIntersectsRect(annotationRect, hitRect);
- });
+
+ MGLAnnotationImage *fallbackAnnotationImage = [self dequeueReusableAnnotationImageWithIdentifier:MGLDefaultStyleMarkerSymbolName];
+ UIImage *fallbackImage = fallbackAnnotationImage.image;
+
+ annotationRect = [self frameOfImage:annotationImage.image ?: fallbackImage centeredAtCoordinate:annotation.coordinate];
+ }
- nearbyAnnotations.resize(std::distance(nearbyAnnotations.begin(), end));
- }
+ // Filter out the annotation if the fattened finger didn’t land
+ // within the image’s alignment rect.
+ return !!!CGRectIntersectsRect(annotationRect, hitRect);
+ });
+
+ nearbyAnnotations.resize(std::distance(nearbyAnnotations.begin(), end));
}