Skip to content

Commit

Permalink
[labeling] Fix data defined placement with rotated maps
Browse files Browse the repository at this point in the history
For layers requiring reprojection and with rotated maps any
labels with data defined x/y would not be rendered

Fix #14236

(cherry-picked from d36fb61)
  • Loading branch information
nyalldawson committed Oct 6, 2016
1 parent 52f702e commit c2fbab1
Showing 1 changed file with 7 additions and 28 deletions.
35 changes: 7 additions & 28 deletions src/core/qgspallabeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2833,35 +2833,14 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
ydiff = yd;
}

//project xPos and yPos from layer to map CRS
double z = 0;
if ( ct )
//project xPos and yPos from layer to map CRS, handle rotation
QgsGeometry ddPoint( new QgsPointV2( xPos, yPos ) );
if ( QgsPalLabeling::geometryRequiresPreparation( &ddPoint, context, ct ) )
{
try
{
ct->transformInPlace( xPos, yPos, z );
}
catch ( QgsCsException &e )
{
Q_UNUSED( e );
QgsDebugMsgLevel( QString( "Ignoring feature %1 due transformation exception on data-defined position" ).arg( f.id() ), 4 );
return;
}
}

//rotate position with map if data-defined
if ( dataDefinedPosition && m2p.mapRotation() )
{
const QgsPoint& center = context.extent().center();
QTransform t = QTransform::fromTranslate( center.x(), center.y() );
t.rotate( -m2p.mapRotation() );
t.translate( -center.x(), -center.y() );
qreal xPosR, yPosR;
qreal xPos_qreal = xPos, yPos_qreal = yPos;
t.map( xPos_qreal, yPos_qreal, &xPosR, &yPosR );
xPos = xPosR;
yPos = yPosR;

QgsGeometry* newPoint = QgsPalLabeling::prepareGeometry( &ddPoint, context, ct );
xPos = static_cast< QgsPointV2* >( newPoint->geometry() )->x();
yPos = static_cast< QgsPointV2* >( newPoint->geometry() )->y();
delete newPoint;
}

xPos += xdiff;
Expand Down

0 comments on commit c2fbab1

Please sign in to comment.