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 5, 2016
1 parent 2cb8ab0 commit e4a9173
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 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
17 changes: 12 additions & 5 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1397,15 +1397,22 @@ - (void)handleSingleTapGesture:(UITapGestureRecognizer *)singleTap

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 = self.userLocationAnnotationView.hitTestLayer.superlayer ? [singleTap locationInView:self.userLocationAnnotationView] : tapPoint;

CALayer *hitLayer = self.userLocationVisible ? [self.userLocationAnnotationView.hitTestLayer hitTest:tapPointForUserLocation] : nil;
if (hitLayer)
{
[self selectAnnotation:self.userLocation animated:YES];
if ( ! _userLocationAnnotationIsSelected)
{
[self selectAnnotation:self.userLocation animated:YES];
}
return;
}
return;
}


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 e4a9173

Please sign in to comment.