我在互联网上搜索,但我找不到这个问题的答案。可以在 MKPolygon 上画一个洞吗?像这样的东西:
我记得我看到过类似的东西,但我不确定它是否与 iOS 有关。有可能做到这一点,(如果是的话)我应该如何开始?
谢谢
要正确执行此操作,您应该真正查看MKPolygoninteriorPolygons
的各个部分。
正如@incanus 指出的那样,您可以定义一个interiorPolygons
数组。例如:
NSUInteger interiorCount = 5;
CLLocationCoordinate2D interiorCoordinates[interiorCount];
interiorCoordinates[0] = CLLocationCoordinate2DMake(...);
interiorCoordinates[1] = CLLocationCoordinate2DMake(...);
interiorCoordinates[2] = CLLocationCoordinate2DMake(...);
interiorCoordinates[3] = CLLocationCoordinate2DMake(...);
interiorCoordinates[4] = CLLocationCoordinate2DMake(...);
MKPolygon* interiorPolygon = [MKPolygon polygonWithCoordinates:interiorCoordinates
count:interiorCount];
interiorPolygon.title = @"interior polygon";
NSUInteger count = 5;
CLLocationCoordinate2D coordinates[count];
coordinates[0] = CLLocationCoordinate2DMake(...);
coordinates[1] = CLLocationCoordinate2DMake(...);
coordinates[2] = CLLocationCoordinate2DMake(...);
coordinates[3] = CLLocationCoordinate2DMake(...);
coordinates[4] = CLLocationCoordinate2DMake(...);
MKPolygon* polygon = [MKPolygon polygonWithCoordinates:coordinates
count:count
interiorPolygons:@[interiorPolygon]];
polygon.title = @"exterior polygon";
[self.mapView addOverlay:polygon];
这会产生:
归功于@incanus!