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:
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
To do this properly, you should really look at the interiorPolygons
parts of MKPolygon.
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:
Credit goes to @incanus!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With