MKOverlayPathRenderer反转填充区域

时间:2017-12-29 13:46:50

标签: ios swift mapkit mkoverlay

我有一个MKOverlayPathRenderer中描述的多边形区域。我没有填写多边形所包含的区域,而是想填写它外面的区域。

如何反转MK​​OverlayPathRenderer的填充区域?

这是获取渲染器的函数:

func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
    let renderer = parser.rendererForOverlay(overlay)! as! MKOverlayPathRenderer
    renderer.fillColor = UIColor.red
    renderer.strokeColor = UIColor.blue
    return renderer
}

1 个答案:

答案 0 :(得分:0)

你可以使用" interiorPolygons"当你绘制叠加时:

CLLocationCoordinate2D polygoneCoords[10]
= { {Point1LAT,Point1LONG}, {Point2LAT,Point2LONG}, {Point3LAT,Point3LONG}, {Point4LAT,Point4LONG},{Point5LAT,Point5LONG},{Point6LAT,Point6LONG},{Point7LAT,Point7LONG},{Point8LAT,Point8LONG},{Point9LAT,Point9LONG},{Point10LAT,Point10LONG}};
self.myPolygoneArea = [MKPolygon polygonWithCoordinates:polygoneCoords count:10];

CLLocationCoordinate2D worldCoords[6] = { {90, 0}, {90, 180}, {-90,180}, {-90,0}, {-90,-180}, {90,-180} };
myOverlay = [MKPolygon polygonWithCoordinates:worldCoords count:6 interiorPolygons:[NSArray arrayWithObject:myPolygoneArea]];

[self.MyMap addOverlay:myOverlay];

-(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay{

MKPolygonRenderer *polygon = [[MKPolygonRenderer alloc]initWithOverlay:overlay];

polygon.strokeColor = [UIColor redColor];
polygon.lineWidth = 2;
polygon.fillColor = [[UIColor blackColor]colorWithAlphaComponent:0.3];

return polygon;}

希望这有帮助...