Skip to content
Permalink
Browse files

[labeling] Fix data defined placement with rotated maps

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 322c8f4 commit 446493d10af202b07ad82bd237e741c849ddb0b3
Showing with 7 additions and 28 deletions.
  1. +7 −28 src/core/qgspallabeling.cpp
@@ -2784,35 +2784,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;

0 comments on commit 446493d

Please sign in to comment.
You can’t perform that action at this time.