Domanda

I searched over the internet but I couldn't find an answer to this. It is possible to draw a hole in a MKPolygon? Something like this:

enter image description here

I remember I saw something like this, but I'm not sure if it was related to iOS. It is possible to do this and (if it is) how I should start?

Thank you

È stato utile?

Soluzione

To do this properly, you should really look at the interiorPolygons parts of MKPolygon.

Altri suggerimenti

As @incanus points out, you can define an interiorPolygons array. For example:

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];

That yields:

overlay with interior polygon

Credit goes to @incanus!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top