我正在使用iPhone的Quartz-2D在地图上显示路线。路线根据温度着色。由于某些街道的颜色是黄色,因此我在路线下方使用稍厚的黑色线条来创建边框效果,以便黄色街道上的黄色部分能够被点亮。但是,即使黑线与路线一样粗糙,整条路线看起来像是一条蠕虫(非常丑陋)。我想这是因为我正在绘制从航点到航点的线路,而不是使用最后一个航点作为下一个起点。这样,如果有几个路标遗失,路线仍然没有削减。iphone石英在彼此的顶部绘制2条线导致蠕虫效应
我需要做什么来显示两条线没有蠕虫效应?
-(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.
错误,我认为这是废话。
请提示我! :)