swift - 是否可以使 MGLPolyLines 可选? - swift , map 框

标签 swift swift4 mapbox polyline mglmapview

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

最佳答案

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

如果您看一下简单的 Mapbox 示例,Annotation Models ,它演示了 MGLPolyline 和间隔的圆形注释,您可以对提供的代码进行简单的修改并亲自查看。演示看起来像这样:

enter image description here

如果您查看 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

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

enter image description here

这个例子子类化了 MGLPolyline (CustomPolyline),所以它的外观可以稍微改变,但不会改变任何关于可点击性的东西。

关于swift - 是否可以使 MGLPolyLines 可选? - swift , map 框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54586620/

相关文章:

swift - iOS 网络扩展错误创建 TUN/TAP 接口(interface) SIOCGIFMTU 失败 : device not configured

ios - Swift 无法将类型 'CGPath' 的值分配给类型 'CGPath?' 的值

javascript - Mapbox GL JS - 带坐标的反向地理编码

swift - 10 _dyid_start - 迁移到 Swift 4 后线程崩溃

swift4 - 如何使用可编码和文件管理器在 swift 4 中保存数据

ios - ios 中的 mapbox direction api 错误路线

javascript - 如何保护 JavaScript API 访问 token ?

ios - 在 Swift 3.0 中使用 NSDataDetector 从字符串中提取地址元素

ios - view.traitCollection.horizo​​ntalSizeClass 在 vi​​ewDidLoad 中返回 undefined (0)

ios - GoogleAuth 在 IOS 中使用 Firebase