[ios] Account for center offset when tapping annotation views (#5931)
This adjusts the tap point for the map's single tap gesture recognizer to use the coordinate to point translated point of the actual annotation the view represents. This fixes an issue where views that were offset in the point coordinate system were not selected when tapped since their associated annotations were actually at the origin of the offset.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
4018B1C91CDC288A00F666AF /* MGLAnnotationView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4018B1C31CDC277F00F666AF /* MGLAnnotationView_Private.h */; };
|
||||
4018B1CA1CDC288E00F666AF /* MGLAnnotationView.h in Headers */ = {isa = PBXBuildFile; fileRef = 4018B1C51CDC277F00F666AF /* MGLAnnotationView.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
4018B1CB1CDC288E00F666AF /* MGLAnnotationView.h in Headers */ = {isa = PBXBuildFile; fileRef = 4018B1C51CDC277F00F666AF /* MGLAnnotationView.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
404326891D5B9B27007111BD /* MGLAnnotationContainerView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 404326881D5B9B1A007111BD /* MGLAnnotationContainerView_Private.h */; };
|
||||
40EDA1C01CFE0E0200D9EA68 /* MGLAnnotationContainerView.h in Headers */ = {isa = PBXBuildFile; fileRef = 40EDA1BD1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.h */; };
|
||||
40EDA1C11CFE0E0500D9EA68 /* MGLAnnotationContainerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 40EDA1BE1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.m */; };
|
||||
40EDA1C21CFE0E0500D9EA68 /* MGLAnnotationContainerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 40EDA1BE1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.m */; };
|
||||
@@ -341,6 +342,7 @@
|
||||
4018B1C41CDC277F00F666AF /* MGLAnnotationView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAnnotationView.mm; sourceTree = "<group>"; };
|
||||
4018B1C51CDC277F00F666AF /* MGLAnnotationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAnnotationView.h; sourceTree = "<group>"; };
|
||||
402E9DE01CD2C76200FD4519 /* Mapbox.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = Mapbox.playground; sourceTree = "<group>"; };
|
||||
404326881D5B9B1A007111BD /* MGLAnnotationContainerView_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLAnnotationContainerView_Private.h; sourceTree = "<group>"; };
|
||||
40EDA1BD1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAnnotationContainerView.h; sourceTree = "<group>"; };
|
||||
40EDA1BE1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLAnnotationContainerView.m; sourceTree = "<group>"; };
|
||||
40FDA7691CCAAA6800442548 /* MBXAnnotationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBXAnnotationView.h; sourceTree = "<group>"; };
|
||||
@@ -929,6 +931,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
40EDA1BD1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.h */,
|
||||
404326881D5B9B1A007111BD /* MGLAnnotationContainerView_Private.h */,
|
||||
40EDA1BE1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.m */,
|
||||
4018B1C51CDC277F00F666AF /* MGLAnnotationView.h */,
|
||||
4018B1C31CDC277F00F666AF /* MGLAnnotationView_Private.h */,
|
||||
@@ -977,6 +980,7 @@
|
||||
DA88482C1CBAFA6200AB86E3 /* NSBundle+MGLAdditions.h in Headers */,
|
||||
DA88488E1CBB047F00AB86E3 /* reachability.h in Headers */,
|
||||
DA8848231CBAFA6200AB86E3 /* MGLOfflineStorage_Private.h in Headers */,
|
||||
404326891D5B9B27007111BD /* MGLAnnotationContainerView_Private.h in Headers */,
|
||||
DA88483B1CBAFB8500AB86E3 /* MGLCalloutView.h in Headers */,
|
||||
DA8848531CBAFB9800AB86E3 /* MGLCompactCalloutView.h in Headers */,
|
||||
DA8847FB1CBAFA5100AB86E3 /* MGLShape.h in Headers */,
|
||||
|
||||
14
platform/ios/src/MGLAnnotationContainerView_Private.h
Normal file
14
platform/ios/src/MGLAnnotationContainerView_Private.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#import "MGLAnnotationContainerView.h"
|
||||
#import "MGLAnnotationView.h"
|
||||
|
||||
@class MGLAnnotationView;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface MGLAnnotationContainerView (Private)
|
||||
|
||||
@property (nonatomic) NS_MUTABLE_ARRAY_OF(MGLAnnotationView *) *annotationViews;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -42,6 +42,7 @@
|
||||
#import "MGLMapboxEvents.h"
|
||||
#import "MGLCompactCalloutView.h"
|
||||
#import "MGLAnnotationContainerView.h"
|
||||
#import "MGLAnnotationContainerView_Private.h"
|
||||
|
||||
#import <algorithm>
|
||||
#import <cstdlib>
|
||||
@@ -1407,6 +1408,18 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
|
||||
}
|
||||
|
||||
CGPoint tapPoint = [singleTap locationInView:self];
|
||||
|
||||
// Handle the case of an offset annotation view by converting the tap point to be the geo location
|
||||
// of the annotation itself that the view represents
|
||||
for (MGLAnnotationView *view in self.annotationContainerView.annotationViews)
|
||||
{
|
||||
if (view.centerOffset.dx != 0 || view.centerOffset.dy != 0) {
|
||||
if (CGRectContainsPoint(view.frame, tapPoint)) {
|
||||
CGPoint annotationPoint = [self convertCoordinate:view.annotation.coordinate toPointToView:self];
|
||||
tapPoint = annotationPoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MGLAnnotationTag hitAnnotationTag = [self annotationTagAtPoint:tapPoint persistingResults:YES];
|
||||
if (hitAnnotationTag != MGLAnnotationTagNotFound)
|
||||
|
||||
Reference in New Issue
Block a user