2010-01-14 3 views
1

J'utilise Quartz-2D pour iPhone pour afficher un itinéraire sur une carte. L'itinéraire est coloré en fonction de la température. Parce que certaines rues sont colorées en jaune, j'utilise une ligne noire légèrement plus épaisse sous la ligne de route pour créer un effet de bordure, de sorte que les parties jaunes de la route sont spottables sur les rues jaunes. Mais, même si la ligne noire est aussi épaisse que la ligne de route, tout le parcours ressemble à un ver (très moche). Je pensais que c'était parce que je dessinais des lignes du waypoint au waypoint, utilisant plutôt le dernier waypoint comme point de départ suivant. Ainsi, s'il manque quelques waypoints, l'itinéraire n'aura toujours pas de coupures.dessin quartz iphone 2 lignes sur le dessus de l'autre provoque un effet de vis sans fin

Que dois-je faire pour afficher les deux lignes sans un effet de ver?

-(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];  
} 
} 

Aussi, je reçois un

<Error>: CGContextClosePath: no current point. 
erreur

, qui je pense est des conneries.

S'il vous plaît allusion à moi! :)


Répondre

0

Cela ressemble peut-être à quelque chose à voir avec les limites de ligne. Essayez de dessiner avec des embouts plats et voyez-le qui vous aide.

MISE À JOUR: Je vois ce qui se passait maintenant. C'est simplement la ligne "background" qui chevauche les pixels couverts par le dessin "background" + "forground" précédent. Votre changement pour dessiner toutes les lignes "d'arrière plan" puis toutes les lignes "d'avant plan" évite ce problème. Vos lignes surlèvent encore quelques pixels, mais seulement de la même couleur, donc vous ne les remarquerez pas. (Notez que la plupart des styles de fin de ligne s'étendent au-delà du point réel de la ligne, accentuant ainsi l'effet - plus de pixels superposés.)

0

Merci les gars! Donc, simplement en ajoutant une ombre ou les bouchons de ligne n'a pas aidé, l'effet est resté le même. Cependant, je viens de jouer avec le code un peu et il s'avère que si je dessine les deux lignes en plein chemin séparément (en deux pour les boucles), l'effet est parti! Ensuite, j'ai ajouté des bouchons carrés à la ligne de fond pour le rendre un peu plus agréable. Maintenant, la seule chose que je me demande est ... quelle est l'explication pour cela? Voici le nouveau code, je vais optimisons plus tard ...

-(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.5); 
     CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor); 
     CGContextSetLineCap(context, kCGLineCapSquare); 
     CGContextMoveToPoint(context, fromPoint.x, fromPoint.y); 
     CGContextAddLineToPoint(context, toPoint.x, toPoint.y); 
     CGContextStrokePath(context); 
     CGContextClosePath(context); 

     fromWaypoint = toWaypoint; 

    } 

    // zweite for schleife 
    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, routeAnnotation.lineColor.CGColor); 
     CGContextSetLineCap(context, kCGLineCapSquare); 
     CGContextMoveToPoint(context, fromPoint.x, fromPoint.y); 
     CGContextAddLineToPoint(context, toPoint.x, toPoint.y); 
     CGContextStrokePath(context); 
     CGContextClosePath(context); 

    } 

    [fromWaypoint release]; 
    } 
}  
0

, je reçois également un

<Erreur>: CGContextClosePath: aucun point en cours.

Le tracé du chemin termine le contexte du chemin actuel.

Questions connexes