Is it possible to make MGLPolyLines selectable? - Swift, MapBox

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 09:56:33

I've just checked back and it looks like this has been implemented though I'm not sure which Mapbox release rolled this out.

If you take a look at the simple Mapbox example, Annotation Models, that demos an MGLPolyline and interspaced circular annotations, you can make a simple mod to the supplied code and see for yourself. The demo looks like this:

If you look into the viewController code, add a couple of lines below the polyline creation:

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

polyline.title = "Polyline"               // New line
polyline.subtitle = "Pretty Poly".        // New line

// Set the custom `color` property, later used in the `mapView:strokeColorForShapeAnnotation:` delegate method.
polyline.color = .darkGray

Now you can tap and see a basic callout:

This example subclasses MGLPolyline (CustomPolyline) so that its appearance can be altered slightly but that doesn't change anything with regards to the tappability.

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