5

我在互联网上搜索,但我找不到这个问题的答案。可以在 MKPolygon 上画一个洞吗?像这样的东西:

在此处输入图像描述

我记得我看到过类似的东西,但我不确定它是否与 iOS 有关。有可能做到这一点,(如果是的话)我应该如何开始?

谢谢

4

2 回答 2

8

要正确执行此操作,您应该真正查看MKPolygoninteriorPolygons的各个部分。

于 2013-05-21T20:32:02.693 回答
2

正如@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!

于 2013-05-21T15:44:58.477 回答