Skip to content

Commit

Permalink
Fix curved labels ignore line orientation placement flag (fix #5778)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 10, 2015
1 parent 5f2d98c commit 11be444
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/core/pal/feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,12 +871,31 @@ namespace pal
return 0;
}

//calculate overall angle of line
double lineAngle;
double bx = mapShape->x[0];
double by = mapShape->y[0];
double ex = mapShape->x[ mapShape->nbPoints - 1 ];
double ey = mapShape->y[ mapShape->nbPoints - 1 ];
if ( qgsDoubleNear( ey, by ) && qgsDoubleNear( ex, bx ) )
{
lineAngle = 0.0;
}
else
lineAngle = atan2( ey - by, ex - bx );

// find out whether the line direction for this candidate is from right to left
bool isRightToLeft = ( lineAngle > M_PI / 2 || lineAngle <= -M_PI / 2 );

QLinkedList<LabelPosition*> positions;
double delta = qMax( li->label_height, total_distance / 10.0 );

unsigned long flags = mLF->layer()->arrangementFlags();
if ( flags == 0 )
flags = FLAG_ON_LINE; // default flag
// placements may need to be reversed if using line position dependent orientation
// and the line has right-to-left direction
bool reversed = ( !( flags & FLAG_MAP_ORIENTATION ) ? isRightToLeft : false );

// generate curved labels
for ( int i = 0; i*delta < total_distance; i++ )
Expand Down Expand Up @@ -916,15 +935,14 @@ namespace pal
//std::cerr << "cost " << angle_diff << " vs " << costCenter << std::endl;
slp->setCost( cost );


// average angle is calculated with respect to periodicity of angles
double angle_avg = atan2( sin_avg / li->char_num, cos_avg / li->char_num );
// displacement
if ( flags & FLAG_ABOVE_LINE )
if (( !reversed && ( flags & FLAG_ABOVE_LINE ) ) || ( reversed && ( flags & FLAG_BELOW_LINE ) ) )
positions.append( _createCurvedCandidate( slp, angle_avg, mLF->distLabel() ) );
if ( flags & FLAG_ON_LINE )
positions.append( _createCurvedCandidate( slp, angle_avg, -li->label_height / 2 ) );
if ( flags & FLAG_BELOW_LINE )
if (( !reversed && ( flags & FLAG_BELOW_LINE ) ) || ( reversed && ( flags & FLAG_ABOVE_LINE ) ) )
positions.append( _createCurvedCandidate( slp, angle_avg, -li->label_height - mLF->distLabel() ) );

// delete original candidate
Expand Down

0 comments on commit 11be444

Please sign in to comment.