I have built a custom MKOverlayRenderer in order to build polygons, apply a blend mode, then add them to the map view. In my drawMapRect function, I use an array of CGPoints to build the polygon, and create a path.
However, during runtime nothing shows on my map view. My best guess would be the order of which I create the polygon in my drawMapRect function. Any help or guidance would be greatly appreciated, thanks!
override func drawMapRect(mapRect: MKMapRect, zoomScale: MKZoomScale, inContext context: CGContext) {
super.drawMapRect(mapRect, zoomScale: zoomScale, inContext: context)
CGContextSaveGState(context)
CGContextSetBlendMode(context, CGBlendMode.Exclusion)
CGContextSetFillColorWithColor(context, self.fillColor)
CGContextSetStrokeColorWithColor(context, UIColor.whiteColor().CGColor)
CGContextSetLineWidth(context, 1.0)
let point = MKMapPointForCoordinate(self.polygon.points[0])
CGContextMoveToPoint(context, CGFloat(point.x), CGFloat(point.y))
for i in 1..<self.polygon.points.count {
let point = polygon.points[i]
let p = MKMapPointForCoordinate(point)
CGContextAddLineToPoint(context, CGFloat(p.x), CGFloat(p.y))
}
CGContextClosePath(context)
CGContextDrawPath(context, CGPathDrawingMode.FillStroke)
CGContextRestoreGState(context)
}
Here is where my custom overlay renderer is initialized:
func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer {
if (overlay is MKPolygon) {
let polygonRenderer = MyCustomMapRenderer(overlay: overlay, fillColor: self.polyFactory!.getPolygonColor().CGColor, polygon: self.currentPolygon!)
return polygonRenderer
}
return MKOverlayRenderer()
}