2

I have a very specific use case with MKMapView. I generate a big amount of MKPolygons (about 15000) and render them on an overlay. To increase the performance I do following steps:

  1. add one single overlay to the map view which is of size of the wholeWorld
  2. In - (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context I check every polygon if it is contained in the current MapRect (because MapKit divides the map into tiles and renders them in parallel on different threads)
  3. If the polygon is present in the current rect I create a CGPath and fill it with associated color.

Everything worked fine before I changed the blending mode to kCGBlendModeMultiply. After that, I observe some weird and arbitrary rendering artefacts which I can not explain. I made a few screenshots to describe the problem:

http://postimg.org/image/lzj1swss9/

http://postimg.org/image/c0thsotyx/

Here is the code I use in - (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context:

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
{
   [super drawMapRect:mapRect zoomScale:zoomScale inContext:context];
   CGContextSaveGState(context);
   CGContextSetBlendMode(context, kCGBlendModeMultiply);

   NSArray *polygons = ((IndexPolygonsMapOverlay *) self.overlay).polygons;
   @autoreleasepool {
        for (MYMKPolygonSubClass *poly in polygons) {
             if (!MKMapRectIntersectsRect(poly.boundingMapRect, mapRect)) {
                  continue;
             }
             if (!poly.color) continue;
             CGContextSaveGState(context);
             CGContextSetFillColorWithColor(context, poly.color.CGColor);

             CGContextMoveToPoint(context, (CGFloat) poly.points[0].x, (CGFloat) poly.points[0].y);
             for (int idx = 1; idx < poly.pointCount; idx ++) {
                  CGContextAddLineToPoint(context, (CGFloat) poly.points[idx].x, (CGFloat) poly.points[idx].y);
             }
             CGContextClosePath(context);
             CGContextDrawPath(context, kCGPathFill);
             CGContextRestoreGState(context);
        }
   }
   CGContextRestoreGState(context);
}

Did anyone have a similar experience with Multiply Blending Mode, expecially when using it on a MKMapView?

OlegLanger
  • 41
  • 4

0 Answers0