Search code examples
iosswiftcore-graphicsmkoverlay

MKOverlayRenderer draw line using CGPath


I'm trying to draw a line using MKOverlayRenderer. My overlay renderer's drawMapRect is roughly:

let path = CGPathCreateMutable()
CGPathMoveToPoint(path, nil, x, y) // x, y = starting point

let remainingPoints: [CGPoint] = ... // remaining points
CGPathAddLines(path, nil, remainingPoints, remainingPoints.count)

CGContextAddPath(context, path)

CGContextSetStrokeColorWithColor(context, UIColor.blueColor().CGColor)
CGContextSetLineWidth(context, 2.0)

CGContextStrokePath(context)

This however doesn't work, nothing appears. I also tried stroking with:

CGContextDrawPath(context, .Stroke)

I know my path is defined correctly because if I use .FillStroke, it fills the polygons.

Closing the path using CGPathCloseSubpath(path) doesn't help.


Solution

  • My line width (2.0) was too small the for the zoom level.