gpt4 book ai didi

ios - 近距离放大时折线消失

转载 作者:行者123 更新时间:2023-12-01 19:40:10 24 4
gpt4 key购买 nike

我创建了七条不同的折线。但是,当我仔细放大时,其中一些正在消失。为什么会这样?我怎样才能防止这种情况?

这是我的折线渲染器:

func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {

let renderer = MKPolylineRenderer(polyline: overlay as! MKPolyline)
renderer.strokeColor = UIColor(red: 1, green: 1, blue: 1, alpha: 0.9)
renderer.lineWidth = 2.2
return renderer
}

//Thousands of parameters sending as a parameter
func createPathWithPoints(_ points: [MKMapPoint]) {
let arc = MKPolyline(points: points, count: points.count)
mapView.addOverlay(arc)
}

请帮忙!

最佳答案

我在使用 MKPolyline 时遇到了类似的问题,下面是我为解决此问题所做的工作。

1) 确保您在 viewDidLoad() 中有您的 mapView 委托(delegate)。

mapView.delegate = self

2)将您的叠加层添加到 map 中。
mapView.addOverlay(polyLine())

我在我的项目中使用 coredata,所以如果 myLocations 是空的,那么我返回空的 MKPolyline()
private func polyLine() -> MKPolyline {
guard let locations = myLocations else {
return MKPolyline()
}

// Coordinates
let coords: [CLLocationCoordinate2D] = locations.map { location in
let location = location as! Location
return CLLocationCoordinate2D(latitude: location.latitude, longitude: location.longitude)
}

return MKPolyline(coordinates: coords, count: coords.count)
}

3) 我们可以从 MKMapViewDelegate 访问 rendererFor。您可以更改折线的颜色和宽度。
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
guard let polyline = overlay as? MKPolyline else {
return MKOverlayRenderer(overlay: overlay)
}

// Setup renderer
let renderer = MKPolylineRenderer(polyline: polyline)
renderer.strokeColor = .systemBlue
renderer.lineWidth = 3

return renderer
}

关于ios - 近距离放大时折线消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54631738/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com