Skip to content
Permalink
Browse files
Fix placement of annotation items in WMS GetMap
  • Loading branch information
mhugent committed Jun 6, 2021
1 parent 25ca993 commit feff27e4a6f206b2f9873ab7fe97d7d6808bed70
Showing with 28 additions and 3 deletions.
  1. +27 −2 src/server/services/wms/qgswmsrenderer.cpp
  2. +1 −1 src/server/services/wms/qgswmsrenderer.h
@@ -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();
@@ -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();
@@ -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();
}
}

@@ -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;

0 comments on commit feff27e

Please sign in to comment.