4

I have an MKMapView with 2 overlays. They represent 1. The route someone has taken. 2. A series of circular regions of interest. In order to update either of the overlays I update their data, then invalidate their related view:

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

The problem is that adding a single line to my RoutePolyline and invalidating its related view causes every overlay view to be redrawn about 80 times. Given that this happens for every location update this 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 could be causing these extra redraws?

Undistraction
  • 42,754
  • 56
  • 195
  • 331
  • I think you might want to use something like [Apple's Breadcrumb example](https://developer.apple.com/library/ios/#samplecode/Breadcrumb/Introduction/Intro.html). Take a look at `CrumbPath` and `CrumbPathView`. – myell0w Dec 31 '11 at 12:46
  • That's not the apple example code, it's code using some of the apple example code to demonstrate a different thing (faking corelocation). Sample code here: https://developer.apple.com/library/ios/#samplecode/Breadcrumb/Introduction/Intro.html – Diziet Feb 20 '12 at 09:17
  • Hey, can you tell me where you got the method:MKUtils newPolyPathWithPolyline? I can't seem to find it in mkmapkit anywhere. – bobsmells Aug 25 '13 at 19:38

0 Answers0