ios - 如何更改 MGLPolyline 的颜色?
问题描述
如何更改 MGLPolyline 的颜色?我看过这里,但答案不起作用。我还尝试了一些其他代码,但它过于依赖苹果地图。那么我怎样才能改变线条的颜色,最好还能编辑线条的其他方面呢?Bellow 是我相信我应该进行这些编辑的代码的地方,但我不是 100%。
@objc func useButtonTap(_ sender: UIGestureRecognizer) {
print("use tap button pressed")
startButton.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.9)
useTrackButton.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.9)
locationManager?.stopUpdatingLocation()
print(locationList, "<-- location manager array in use button")
if locationList == [] {
print("nothing was tracked")
} else {
var mapCoordinates: [CLLocationCoordinate2D] = []
for locationT in locationList {
print(locationT, "<-- locationT")
print(locationT.coordinate.latitude, "<-- latitude")
print(locationT.coordinate.longitude, "<-- longitude")
let locationLatitude = locationT.coordinate.latitude
let locationLongitude = locationT.coordinate.longitude
print(locationLatitude, "lat")
print(locationLongitude, " long")
let newCoord = CLLocationCoordinate2D(latitude: locationLatitude, longitude: locationLongitude) // - (0.0001/2)
print(newCoord, "<-- new coord")
mapCoordinates.append(newCoord)//+ 0.0001
}
polyline = MGLPolyline(coordinates: mapCoordinates, count: UInt(mapCoordinates.count))
// toCome = polyline
// mapView.add(polyline)
mapView.addAnnotation(polyline) //used to be jsut .add, changed in order to try anwser for color chaning of polyline
}
}
解决方案
你必须做mapView.delegate = self
然后实现这个方法:
func mapView(_ mapView: MGLMapView, strokeColorForShapeAnnotation annotation: MGLShape) -> UIColor {
return .blue
}
推荐阅读
- python - Django-autocomplete-light 显示空下拉列表而不是自动完成小部件
- python - 将分类管道应用于数据集的子集
- firebase - Flutter StreamBuilder 从 Firestore 返回 null
- c# - 为什么我动态添加的事件处理程序没有持续触发
- html - 显示模态时模糊div中的内容?
- amazon-dynamodb - 为什么 dynamoose 只在很短的时间内存储数据?
- javascript - 浏览器自动完成的字段不更新 Angular 绑定变量
- bash - 术语陷阱(Bash)是否比编程中的通用“回调”术语更准确?
- mongodb - mongodb json验证在独立的mongo中不起作用
- azure-data-factory - 通过 ADF V2 到 ADLS Gen2 的本地 SQL 服务器