我正在使用 Quartz-2D for iPhone 在地图上显示路线。路线根据温度着色。因为有些街道是黄色的,所以我在路线下方使用了一条稍粗的黑线来创建边框效果,这样路线的黄色部分就可以在黄色街道上看到。但是,即使黑线和路线线一样粗,整条路线看起来也像一条虫子(非常丑陋)。我认为这是因为我在从航点到航点画线,而不是使用最后一个航点作为下一个起始航点。这样,如果缺少几个航点,路线仍然不会有任何削减。
我需要做什么才能在没有蠕虫效果的情况下显示两条线?
-(void) drawRect:(CGRect) rect
{
CSRouteAnnotation* routeAnnotation = (CSRouteAnnotation*)self.routeView.annotation;
// only draw our lines if we're not int he moddie of a transition and we
// acutally have some points to draw.
if(!self.hidden && nil != routeAnnotation.points && routeAnnotation.points.count > 0)
{
CGContextRef context = UIGraphicsGetCurrentContext();
Waypoint* fromWaypoint = [[Waypoint alloc] initWithDictionary:[routeAnnotation.points objectAtIndex:0]];
Waypoint* toWaypoint;
for(int idx = 1; idx < routeAnnotation.points.count; idx++)
{
toWaypoint = [[Waypoint alloc] initWithDictionary:[routeAnnotation.points objectAtIndex:idx]];
CLLocation* fromLocation = [fromWaypoint getLocation];
CGPoint fromPoint = [self.routeView.mapView convertCoordinate:fromLocation.coordinate toPointToView:self];
CLLocation* toLocation = [toWaypoint getLocation];
CGPoint toPoint = [self.routeView.mapView convertCoordinate:toLocation.coordinate toPointToView:self];
routeAnnotation.lineColor = [fromWaypoint.weather getTemperatureColor];
CGContextBeginPath(context);
CGContextSetLineWidth(context, 3.0);
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextMoveToPoint(context, fromPoint.x, fromPoint.y);
CGContextAddLineToPoint(context, toPoint.x, toPoint.y);
CGContextStrokePath(context);
CGContextClosePath(context);
CGContextBeginPath(context);
CGContextSetLineWidth(context, 3.0);
CGContextSetStrokeColorWithColor(context, routeAnnotation.lineColor.CGColor);
CGContextMoveToPoint(context, fromPoint.x, fromPoint.y);
CGContextAddLineToPoint(context, toPoint.x, toPoint.y);
CGContextStrokePath(context);
CGContextClosePath(context);
fromWaypoint = toWaypoint;
}
[fromWaypoint release];
[toWaypoint release];
}
}
另外,我得到一个
<Error>: CGContextClosePath: no current point.
错误,我认为这是胡说八道。
请提示我!:)