Mapbox 标注图像

Mapbox Callout Image

我对 Mapbox 标注有疑问。我想知道是否可以将标准的白色标注背景变成图像。我希望我的注释标注具有此图像,并在单击时转到显示该位置的大图像的视图控制器。我通常会使用右侧或左侧的 calloutAccessoryView 按钮,但是,我已经将这两个按钮用于不同的功能。有人知道这是否可能吗?我做了一些研究,似乎没有明确的方法来创建它(尽管在 MapKit 中它看起来非常简单!!)。

是的,你可以这样做,它内置于 Mapbox API。您使用 MGLMapViewDelegate 方法 optional func mapView(_ mapView: Any!, tapOnCalloutForAnnotation annotation: Any!) 来自网站:

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