How to make a MGLPolyline tapable?

混江龙づ霸主 提交于 2019-12-11 07:20:54

问题


I am currently looking for a way to make a route (MGPLPolyline) tappable such that a user can choose between two possible routes under Mapbox. Unfortunately the route annotation doesn't seem to be tappable at all:

While i have properly set my MGLMapViewDelegate this method:

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

is never invoked.

What did i miss knowing that each line inherited from MGLPolyline which is a subclass of an MGLAnnotation (which i was expected to be tappable...).


回答1:


The Mapbox iOS API doesn't support that yet, unfortunately. See here.

There are a couple of workarounds within that link that you could try though.

UPDATE: This is now possible: Check here.




回答2:


You could do the following:

First, when you create the polyline do the following:

let polyline = CustomPolyline(coordinates: &coordinates, count: UInt(coordinates.count))

polyline.title = "" //It does not seem to matter what you set it to.

polyline.color = .darkGray

Then in the following method return false:

 func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
    // Always allow callouts to popup when annotations are tapped.
    print("ran?")
    return false
}


来源:https://stackoverflow.com/questions/43683846/how-to-make-a-mglpolyline-tapable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!