Search code examples
iosintersectionmkpolylinemkpolygon

Creating a new MKPolygon from two intersecting polygons


I know that there is exactly one specific question that talks about this but its a bit old and I wanted to get a little more technical about it if possible.

First of all take a look at this screenshot: https://www.dropbox.com/s/f94q3qaxrog0ec9/intersections.png

Want I want to have happen is say "I see where they both intersect and where that happens I do not want to draw those 'parts' of the polygon". In this case i would like to draw both polygons but not draw the 'path' of the yellow polygon that is inside the orange polygon. This include not only the line but the fill color as well.

Obviously this gets tricky because you aren't always going to have exact points along the path of each polygon that intersect exactly with other points along another polygon path. As you can see from this screenshot, in order to make this possible, I think, I need to get the points back where they do intersect.

After that and assuming that I can do this, I do not know if there is a way to use the CGPathRef class to do what i need to do. Obviously I am going to have re-create a polygon but according to the docs you cant fill it in unless it is a closed path. So how do you fill in the polygon that is not interesecting without closing the path??

The only thing that i can think of would be to "hide" the parts of the polygon that intersect but unsure how to do this. Can anyone offer any help/insight to this problem??


Solution

  • Ok guys! well i went off and created my own MKPolygon category to solve what i needed to solve. I hope it is also useful to others!

    the github link is: https://github.com/geeksweep/MKPolygon-GSPolygonIntersections