Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios] Hit test the user location annotation dot specifically
Browse files Browse the repository at this point in the history
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 e4a9173.
  • Loading branch information
friedbunny committed Aug 7, 2016
1 parent b928ac5 commit ae88c01
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
18 changes: 11 additions & 7 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1392,17 +1392,21 @@ - (void)handleSingleTapGesture:(UITapGestureRecognizer *)singleTap
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)
Expand Down
1 change: 1 addition & 0 deletions platform/ios/src/MGLUserLocationAnnotationView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions platform/ios/src/MGLUserLocationAnnotationView.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ - (void)setTintColor:(UIColor *)tintColor
}
}

- (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))
Expand Down

0 comments on commit ae88c01

Please sign in to comment.