Optimized Polyline drawing drawMapRect

I have many long polylines on the map. I would like to optimize their drawing, because at several thousand points the polylines are drawn incredibly slowly.

My drawMapRect looks like this:

 - for each polyline segment - verify if it bounding box intersects the currently drawn MKMapRect - if id does, draw it 

Which is great if not so many points. But with 8-16 cards and 2-3000 points, they incredibly slowly go through for .

If they were only locations, the solution would be to implement some kind of quadtree / r-tree structure and only a filter for these locations in the current MKMapRect drawing, but I'm not sure what this will be for the polylines themselves.

If I filter only for the endpoints of a segment inside the current layout, then some line segments may not be displayed. For example, two red changes between points 1-2 do not have segment endpoints in them, but they still need to be drawn ...

enter image description here

Is there some kind of quadrant-like algorithm or some kind of approach for this problem?

+5
source share
1 answer

Unfortunately, I do not know such a data structure that would allow checking the intersection of a line with a rectangle.
However, one way to solve the problem could be the following:
Draw all the polylines on the map with a very low resolution (2-dimensional array) and pay attention to each pixel that the polyline has drawn. Then scan the corresponding rectangles for the drawn pixels into this low-resolution map and save all the corresponding polylines. Then they can be displayed on a full resolution map.
Perhaps this approximate algorithm is faster than the exact algorithm that you are using right now.

EDIT:

I assume that you are using an efficient algorithm to intersect the MKMapRect polyline, such as shown in How to find the intersection point between a line and a rectangle? .

0
source

Source: https://habr.com/ru/post/1236220/


All Articles