是否可以使 MGLPolyLines 可选? - Swift, 地图框

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

是否可以进行 MGLPolyLine touchable/selectable/have 用户交互?在我的项目中,用户需要触摸折线。之前有 问过,但它已经过时了大约 2 年。他们(MapBox)更新了吗?

我刚回来查看,看起来这已经实现了,但我不确定是哪个 Mapbox 版本推出的。

如果您看一下演示 MGLPolyline 和间隔圆形注释的简单 Mapbox 示例 Annotation Models,您可以对提供的代码进行简单的 mod 并亲自查看。演示如下所示:

如果您查看 viewController 代码,请在折线创建下方添加几行:

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

现在您可以点按并查看基本标注:

此示例对 MGLPolyline (CustomPolyline) 进行了子类化,因此可以稍微更改其外观,但不会改变可点击性方面的任何内容。