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

Commit

Permalink
[ios] Add MGLUserLocationAnnotationView.hitTestLayer property
Browse files Browse the repository at this point in the history
And implement this property in MGLFaux3DUserLocationAnnotationView.

Generic reimplementation of #5816.
  • Loading branch information
friedbunny committed Aug 9, 2016
1 parent 2dfcccf commit 7aec17d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
6 changes: 6 additions & 0 deletions platform/ios/src/MGLFaux3DUserLocationAnnotationView.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ - (void)didUpdateUserLocation:(MGLUserLocation *)userLocation
[self setupLayers];
}

- (CALayer *)hitTestLayer
{
// only the main dot should be interactive (i.e., exclude the halo)
return _dotBorderLayer ?: _puckDot;
}

- (void)setTintColor:(UIColor *)tintColor
{
if (_puckModeActivated)
Expand Down
5 changes: 3 additions & 2 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1395,10 +1395,13 @@ - (void)handleSingleTapGesture:(UITapGestureRecognizer *)singleTap
return;
}

CGPoint tapPoint = [singleTap locationInView:self];

if (self.userLocationVisible)
{
CGPoint tapPointForUserLocation = [singleTap locationInView:self.userLocationAnnotationView];
CALayer *hitLayer = [self.userLocationAnnotationView.hitTestLayer hitTest:tapPointForUserLocation];

if (hitLayer)
{
if ( ! _userLocationAnnotationIsSelected)
Expand All @@ -1408,8 +1411,6 @@ - (void)handleSingleTapGesture:(UITapGestureRecognizer *)singleTap
return;
}
}

CGPoint tapPoint = [singleTap locationInView:self];

MGLAnnotationTag hitAnnotationTag = [self annotationTagAtPoint:tapPoint persistingResults:YES];
if (hitAnnotationTag != MGLAnnotationTagNotFound)
Expand Down
15 changes: 13 additions & 2 deletions platform/ios/src/MGLUserLocationAnnotationView.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,23 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly, weak, nullable) MGLMapView *mapView;

/**
Returns the annotation object indicating the user's current location.
Returns the annotation object indicating the users current location.
The value of this property is nil during initialization and while user tracking is inactive.
The value of this property is nil during initialization and while user tracking
is inactive.
*/
@property (nonatomic, readonly, weak, nullable) MGLUserLocation *userLocation;

/**
Returns the layer that should be used for annotation selection hit testing.
The default value of this property is the presentation layer of the view’s Core
Animation layer. When subclassing, you may override this property to specify a
different layer to be used for hit testing. This can be useful when you wish to
limit the interactive area of the annotation to a specific sublayer.
*/
@property (nonatomic, readonly, weak) CALayer *hitTestLayer;

@end

NS_ASSUME_NONNULL_END
6 changes: 6 additions & 0 deletions platform/ios/src/MGLUserLocationAnnotationView.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@interface MGLUserLocationAnnotationView()
@property (nonatomic, weak, nullable) MGLMapView *mapView;
@property (nonatomic, weak, nullable) MGLUserLocation *userLocation;
@property (nonatomic, weak) CALayer *hitTestLayer;
@end

@implementation MGLUserLocationAnnotationView {
Expand All @@ -35,6 +36,11 @@ - (void)didUpdateUserLocation:(MGLUserLocation *)userLocation
// Left blank intentionally. Subclasses may override this in order to customize UI based on course, speed etc.
}

- (CALayer *)hitTestLayer
{
return self.layer.presentationLayer;
}

- (BOOL)isAccessibilityElement
{
return !self.hidden;
Expand Down

0 comments on commit 7aec17d

Please sign in to comment.