1

MKCircle fillColor当 markerType 不同时,我试图进行更改。例如,如果markerType是“机场”,那么填充应该是红色,如果是“Sea Plane Base”,那么填充应该是黑色。

// MARK: Radius overlay
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
    if overlay is MKCircle {
        let circle = MKCircleRenderer(overlay: overlay)

        for markerType in airports {
            if markerType.markerType == "airport" {
                circle.strokeColor = UIColor.red
                circle.fillColor = UIColor(red: 255, green: 0, blue: 0, alpha: 0.1)
                circle.lineWidth = 1
            } else {
                circle.strokeColor = UIColor.black
                circle.fillColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.1)
                circle.lineWidth = 1
            }
        }

        return circle
    } else {
        return MKPolylineRenderer()
    }
}

我正在使用这个函数来显示半径。

func mainAirportRadius(radius: CLLocationDistance) {
    //MARK: Airport location
    for coordinate in airports {
        let center = coordinate.coordinate
        let circle = MKCircle(center: center, radius: radius)
        mapView.add(circle)
    }
}

然后我在viewDidLoad方法中调用它

mainAirportRadius(radius: 8046.72)
4

0 回答 0