Domanda

I am working with MKPolygon and MKPolygonView as a map overlay for the first time. I can place a shape over an area, and the fill color fills the interior of the polygon.

I am looking for a way to put the fill everywhere on my map except the interior of the polygon. Does anyone have an idea how to do this easily?

È stato utile?

Soluzione

One way to do this is by making a polygon overlay that covers the whole world and specifying the part(s) you don't want to fill as "interior polygon(s)".

This is done using the polygonWithCoordinates:count:interiorPolygons: class method of MKPolygon. There's also polygonWithPoints:count:interiorPolygons: if you have MKMapPoints instead of coordinates.

You pass an NSArray of MKPolygons for the interiorPolygons parameter. These areas will not be filled in with the fillColor.

For sample code, see this question: Showing Specific Region Using MapKit

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