MKMapView - redrawing overlays in the most efficient way

I have a MKMapView with two overlays. They represent 1. The route that someone took. 2. A number of interesting circular areas. To update both overlays, I update their data and then invalidate their associated views:

[(RoutePolyline *)self.overlay appendPolylines:polylines]; MKOverlayPathView *overlayView = (MKOverlayPathView *)[self.mapView viewForOverlay:self.overlay]; [overlayView invalidatePath]; 

The problem is that adding a separate line to my RoutePolyline and canceling the view associated with it leads to the fact that each overlay view will be redrawn about 80 times. Given that this happens for every location update, it is incredibly expensive.

Here is the code from the only method in my RouteOverlayView:

 - (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context { RoutePolyline *routePolyline = (RoutePolyline *)self.overlay; int polylineCount = [routePolyline.polylines count]; for (int i = 0; i < polylineCount; i++) { MKPolyline *polyline = [routePolyline.polylines objectAtIndex:i]; CGPathRef path = [MKUtils newPolyPathWithPolyline:polyline overlayView:self]; if (path) { [self applyFillPropertiesToContext:context atZoomScale:zoomScale]; CGContextBeginPath(context); CGContextAddPath(context, path); CGContextDrawPath(context, kCGPathStroke); [self applyStrokePropertiesToContext:context atZoomScale:zoomScale]; CGContextBeginPath(context); CGContextAddPath(context, path); CGContextStrokePath(context); CGPathRelease(path); } } } 

What can cause additional redraws?

+4
source share

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


All Articles