I’m developing an application that’s tracing lines of highways on the Google Maps SDK Add-On.
There are a lot of points painted, which inadvertently make the Maps very sluggish to navigate. It seems iOS Maps take care of this issue, as a significant amount of points can be drawn without the maps becoming sluggish.
I started sampling points depending on zoom level. E.g. zoom level 7 only uses, and draws lines to, every 20th point to trace the route. But even that is still too many points and ends up with a very sluggish panning and zooming experience.
Two questions:
One: Is it possible to detect the current region of the map being displayed in the phone, and no longer paint points off-screen?
EDIT – after some initial investigation it’s easily possible to detect the clipping region and not paint points/lines. quickReject is the function I’ve used for this. It does not help too much with performance as all points are still being traversed to identify if they must be drawn – I’m sure it can be optimized.
Two: Is it at all possible to cache, perhaps the path, being drawn (this would have to be done per zoom level, I assume, due to the projection of the point?)
Yes, you can get the projection of the four corners of your screen :
While rendering, you should only select points that lie in these bounds.
See also :
In case you are at a very high zoom level see:
Personally I’ve use route simplification algorithms to reduce the number of points on a straight path. For e.g if 20 points lie in the same line, it makes sense to use the start and end point and drawn a straight line.