Skip to content
Permalink
Browse files
Merge pull request #43571 from mhugent/server_annotation_items
Fix placement of annotation items in WMS GetMap
  • Loading branch information
mhugent committed Jun 15, 2021
2 parents a0e2ee4 + 6f7873e commit 6b10a2137e485896e3ae7ef4dd2efd94f6ee86b3
@@ -877,7 +877,7 @@ namespace QgsWms
painter.reset( layersRendering( mapSettings, *image ) );

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

// painting is terminated
painter->end();
@@ -3281,7 +3281,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();
@@ -3293,7 +3293,39 @@ 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() );
try
{
mapPos = coordTransform.transform( mapPos );
}
catch ( const QgsCsException &e )
{
QgsMessageLog::logMessage( QStringLiteral( "Error transforming coordinates of annotation item: %1" ).arg( e.what() ) );
}
}
const QgsPointXY devicePos = mapSettings.mapToPixel().transform( mapPos );
offsetX = devicePos.x();
offsetY = devicePos.y();
}
else
{
const 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;
@@ -1853,6 +1853,28 @@ def test_wms_getmap_plus_sign(self):
r, h = self._result(self._execute_request_project(qs, p))
self.assertTrue(b"The layer 'test plus' does not exist" in r)

def test_wms_annotation_item(self):
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(os.path.join(self.testdata_path,
'test_project_annotation_item.qgz')),
"SERVICE": "WMS",
"VERSION": "1.3.0",
"REQUEST": "GetMap",
"BBOX": "44.9014,8.20346,44.9015,8.20364",
"CRS": "EPSG:4326",
"WIDTH": "800",
"HEIGHT": "400",
"LAYERS": "points",
"STYLES": ",",
"FORMAT": "image/png",
"DPI": "96",
"MAP_RESOLUTION": "96",
"FORMAT_OPTIONS": "dpi:96"
}.items())])

r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetMap_AnnotationItem")


if __name__ == '__main__':
unittest.main()
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 6b10a21

Please sign in to comment.