I have lots of long polylines on a map. I'd like to optimize their drawing, because at a few thousand points the polylines are drawn incredibly slow.
My drawMapRect
looks like this :
- for each polyline segment
- verify if it's bounding box intersects the currently drawn MKMapRect
- if id does, draw it
Which does great if there aren't too many points. But when there are 8-16 maprects visible and 2-3000 points, they are incredibly slow running throught the for
.
If they would be only locations, a solution would be to implement some kind of quadtree/r-tree structure and only filter for those locations in the currently drawn MKMapRect
, but I'm not sure about if that would be appropiate for the polylines themselves.
If I filter only for the segment endpoints inside the current maprect, then some line segments might not be drawn. For example, the two red maprects between points 1-2 have no segment endpoints in them but still need to draw ...
Is there some kind of algorithm similar to quadtrees or some kind of approach for this problem ?