Skip to content

Commit

Permalink
Fix placement of annotation items in WMS GetMap
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jun 6, 2021
1 parent 25ca993 commit feff27e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
29 changes: 27 additions & 2 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -857,7 +857,7 @@ namespace QgsWms
painter.reset( layersRendering( mapSettings, *image ) );

// rendering step for annotations
annotationsRendering( painter.get() );
annotationsRendering( painter.get(), mapSettings );

// painting is terminated
painter->end();
Expand Down Expand Up @@ -3253,7 +3253,7 @@ namespace QgsWms
}
}

void QgsRenderer::annotationsRendering( QPainter *painter ) const
void QgsRenderer::annotationsRendering( QPainter *painter, const QgsMapSettings &mapSettings ) const
{
const QgsAnnotationManager *annotationManager = mProject->annotationManager();
const QList< QgsAnnotation * > annotations = annotationManager->annotations();
Expand All @@ -3265,7 +3265,32 @@ namespace QgsWms
if ( !annotation || !annotation->isVisible() )
continue;

//consider item position
double offsetX = 0;
double offsetY = 0;
if ( annotation->hasFixedMapPosition() )
{
QgsPointXY mapPos = annotation->mapPosition();
if ( mapSettings.destinationCrs() != annotation->mapPositionCrs() )
{
QgsCoordinateTransform coordTransform( annotation->mapPositionCrs(), mapSettings.destinationCrs(), mapSettings.transformContext() );
mapPos = coordTransform.transform( mapPos );
}
QgsPointXY devicePos = mapSettings.mapToPixel().transform( mapPos );
offsetX = devicePos.x();
offsetY = devicePos.y();
}
else
{
QPointF relativePos = annotation->relativePosition();
offsetX = mapSettings.outputSize().width() * relativePos.x();
offsetY = mapSettings.outputSize().height() * relativePos.y();
}

painter->save();
painter->translate( offsetX, offsetY );
annotation->render( renderContext );
painter->restore();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/services/wms/qgswmsrenderer.h
Expand Up @@ -156,7 +156,7 @@ namespace QgsWms
QPainter *layersRendering( const QgsMapSettings &mapSettings, QImage &image ) const;

// Rendering step for annotations
void annotationsRendering( QPainter *painter ) const;
void annotationsRendering( QPainter *painter, const QgsMapSettings &mapSettings ) const;

// Set layer opacity
void setLayerOpacity( QgsMapLayer *layer, int opacity ) const;
Expand Down

0 comments on commit feff27e

Please sign in to comment.