Created
September 30, 2010 18:39
-
-
Save ajmath/605077 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Overridden MKOverlayView method that draws the overlay to the MapView | |
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context | |
{ | |
//Create CGPath to be rendered | |
CGMutablePathRef cgPath = CGPathCreateMutable(); | |
CGPoint p1, p2, p3; | |
p1.x = -40; | |
p1.y = 20; | |
p2.x = 0.0; | |
p2.y = -20; | |
p3.x = 40; | |
p3.y = 20; | |
CGPathMoveToPoint(cgPath, NULL, p1.x, p1.y); | |
CGPathAddLineToPoint(cgPath, NULL, p2.x, p2.y); | |
CGPathMoveToPoint(cgPath, NULL, p2.x, p2.y); | |
CGPathAddLineToPoint(cgPath, NULL, p3.x, p3.y); | |
CGPathMoveToPoint(cgPath, NULL, p3.x, p3.y); | |
CGPathAddLineToPoint(cgPath, NULL, p1.x, p1.y); | |
CGPathCloseSubpath(cgPath); | |
//Get a CGPoint that the path will be centered on | |
MKMapPoint mp = MKMapPointForCoordinate(point.coordinate); | |
CGPoint origin = [self pointForMapPoint:mapRect.origin]; | |
//Translate and add the path to the current CGContext | |
CGContextSaveGState(context); | |
CGContextTranslateCTM(context, origin.x, origin.y); | |
CGContextAddPath(context, cgPath); | |
CGContextRestoreGState(context); | |
CGFloat lineWidth = MKRoadWidthAtZoomScale(zoomScale) / 2.0f; | |
//Set CG variables and stroke/fill the path | |
CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 0.5); | |
CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 0.5); | |
CGContextSetLineJoin(context, kCGLineJoinBevel); | |
CGContextSetLineCap(context, kCGLineCapRound); | |
CGContextSetLineWidth(context, lineWidth); | |
CGContextStrokePath(context); | |
CGContextFillPath(context); | |
CGPathRelease(cgPath); | |
} |
CGContextSaveGState(context);
//CGContextTranslateCTM(context, origin.x, origin.y);
CGContextAddPath(context, path);
CGContextRestoreGState(context);
CGFloat lineWidth= MKRoadWidthAtZoomScale(zoomScale) / 2.0f;
//Set CG variables and stroke/fill the path
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextSetRGBFillColor(context, r, b, g, 0.5);
CGContextSetLineJoin(context, kCGLineJoinBevel);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, lineWidth);
//CGContextStrokePath(context);
CGContextFillPath(context);
CGPathRelease(path);
i commented two lines of ur code and it worked
@superaly Thanks for the comment!
Thats weird that it doesn't work with TranslateCTM.
I actually ended up combining CGContextStrokePath and CGContextFillPath with CGContextDrawPath and it worked. I still don't see why you cant use them both separately.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This method will currently stroke the path at the desired location but I cannot get the path filled at all. Any ideas on why its not working?