Search code examples
imagefirebasemapboxcallout

Mapbox Callout Image


I have a question about Mapbox Callouts. I was wondering if it was possible to turn the standard white callout background into an image. I want my annotation callout to have this image and when clicked segue to a view controller displaying a large image of the location. I would normally use a right or left calloutAccessoryView button, however, I am already using these two buttons for different functions. Does anybody know if this is possible? I have done a fair bit of research and it seems that there are no definite ways of creating this (although it seems extremely simple in MapKit!!).


Solution

  • Yes, you can do this, it's built into the Mapbox API. You use the MGLMapViewDelegate method optional func mapView(_ mapView: Any!, tapOnCalloutForAnnotation annotation: Any!) From the website:

    This method is called when the user taps on the body of the callout view, as opposed to the callout’s left or right accessory view. If the annotation has a custom callout view via the -mapView:calloutViewForAnnotation: method, this method is only called whenever the callout view calls its delegate’s -[MGLCalloutViewDelegate calloutViewTapped:] method.

    If this method is present on the delegate, the standard callout view’s body momentarily highlights when the user taps it, whether or not this method does anything in response to the tap.

    Example usage