views:

133

answers:

2

I have created a whole heap of overlays using MKPolygon and created into a MKPolygonView. This works fine but one of the overlays has a butt load of points (about 800 points) and this causes memory and performance issues. I tried shouldRasterize on the MKPolygonView but this had the opposite affect which I am not surprised.

Is there any other thing I can do to increase the performance of it besides lowing the amount of points (which I am in the process of doing)?

A: 

This is an issue that is known by Apple but unlikely to change. Basically anything more then a couple of MKOverlayViews you will have performance issues no matter what your hardware. What you have to basically do is to subclass MKPolygonView and merge all the MKPolygons into one MKPolygonView.

Code is available on Apple Forums but as I didn't write it I don't think I should post it here.

Rudiger
Bingy's suggestion of simplifying the polygon helps a bit. Merging the polygons into one view is ideal I think in this situation, however you can't actually do this in 3.2.x ... We can successfully get away with instantiating MKPolygon and MKPolyline (+ related views) in 3.2, but once you try to create a subclass of any of these classes, everything falls apart due to iOS4 conditions in the linking process and such.
Greg Combs
I was of the understanding that overlays was first introduced in iOS4
Rudiger
Yes, that's true, but they're still available for use on iOS 3.2, oddly. I build my app with the 4.1 SDK and set 3.2 as the minimum device target. After some quadruple-checking, MKPolygon, MKPolyline, and their associated "Views" are functional in iOS 3.2 ... I can even do runtime checks to see if those methods are available and they are. I was worried that it wouldn't pass the App Store, but it did! See screenshots on iOS 3.2 at http://www.texlege.com/
Greg Combs
Heh, fair enough. Just for a bit of clarification to simplifying the polygons, I did a heap of testing to try and fix the performance issues when using MKPolygons, Although I would get about a 5% performance increase when lowering the point count by half, it was still way too slow and the detail was so low it wasn't worth displaying. Subclassing and merging meant we could bring back all the detail and the performance was good on even the 3g, although if you are targeting iOS 3.2 this won't help you.
Rudiger
A: 

I would look at reducing the number of points in the polygon. depending on wher you got it from. Most geopatial manipulation data has functions that will alow you to reduce the number of points in a polygon. (all you need to do is supply an accuracy measurement.)

Bingy
Actually this wasn't the problem as originally thought. There are still 800 points but if you merge the MKPolygonView into one it works perfect.
Rudiger