Mapbox (iOS) user annotations covering/preventing touch events from other annotations - use User annotations hit test

504 views Asked by At

I'm having some difficulties with Mapbox iOS.

I'm adding annotations on my map, but when they are very close (actually overlap) to the user annotation (i.e MGLUserLocation) taps do not pass to the other annotations.

I have tried to play with the z-order both for the user annotation (setting it to. 0/-1 or any lower value) while increasing the value of the other annotations but with no success

func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation)

Is always called with the user annotation.

I'm using a custom view for the user annotation and I tried to set its isEnable property false as well. Moreover, when I try to override the override open func tionsetSelected(_ selected: Bool, animated: Bool) In the custom view it is not called (no matter if it's isEnabled is true/false...)

It seems like the "halo" around the user location annotation make any tap to interact with the user annotation only - even if there are other objects that seems to be before it...

I was thinking as a last option to setup aUIGestureRecognizer on the relevant view that the user annotations "hides"... But am I missing something about the special user annotation in Mapbox?

I create a simple project trying to mimic as best as possible the problem in my original project which is not public - Repo

Here is an example of the capability I'm trying to achieve in Google Mapsexample

1

There are 1 answers

0
CloudBalancing On BEST ANSWER

Found the solution which I think it is utilising Mapbox API in the best way: MGLUserLocationAnnotationView has a property called hitTestLayer: CALayer?

You can just override it and supply with the size of the clickable layer you wish to enable.... In my case I don't care for user annotation interaction so I set it to zero (I updated the code in the example repo as well)