[ios] Hit test the user location annotation dot specifically

Rather than try to exclude layers in the touch hit test, this
specifically only checks against the main layer for the user dot or
puck.

Back-port of e4a9173a2a5c585dda3fa7a0f955cff1552f8d25.
This commit is contained in:
Jason Wray
2016-08-06 17:59:35 -07:00
parent b928ac5bd4
commit ae88c01c94
3 changed files with 18 additions and 7 deletions

View File

@@ -1392,17 +1392,21 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
return;
}
CGPoint tapPoint = [singleTap locationInView:self];
CALayer *hitLayer = self.userLocationVisible ? [self.userLocationAnnotationView.layer.presentationLayer hitTest:tapPoint] : nil;
if (hitLayer && hitLayer != self.userLocationAnnotationView.haloLayer.presentationLayer)
if (self.userLocationVisible)
{
if ( ! _userLocationAnnotationIsSelected)
CGPoint tapPointForUserLocation = [singleTap locationInView:self.userLocationAnnotationView];
CALayer *hitLayer = [self.userLocationAnnotationView.hitTestLayer hitTest:tapPointForUserLocation];
if (hitLayer)
{
[self selectAnnotation:self.userLocation animated:YES];
if ( ! _userLocationAnnotationIsSelected)
{
[self selectAnnotation:self.userLocation animated:YES];
}
return;
}
return;
}
CGPoint tapPoint = [singleTap locationInView:self];
MGLAnnotationTag hitAnnotationTag = [self annotationTagAtPoint:tapPoint persistingResults:YES];
if (hitAnnotationTag != MGLAnnotationTagNotFound)

View File

@@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, weak) MGLMapView *mapView;
@property (nonatomic) MGLUserLocation *annotation;
@property (nonatomic, readonly, nullable) CALayer *haloLayer;
@property (nonatomic, readonly) CALayer *hitTestLayer;
- (instancetype)initInMapView:(MGLMapView *)mapView NS_DESIGNATED_INITIALIZER;
- (void)setupLayers;

View File

@@ -147,6 +147,12 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck
}
}
- (CALayer *)hitTestLayer
{
// only the main dot should be interactive (i.e., exclude the accuracy ring and halo)
return _dotBorderLayer ?: _puckDot;
}
- (void)setupLayers
{
if (CLLocationCoordinate2DIsValid(self.annotation.coordinate))