|
@@ -34,16 +34,60 @@ namespace QgsWms |
|
|
Q_UNUSED( version ); |
|
|
|
|
|
QgsServerRequest::Parameters params = request.parameters(); |
|
|
QString format = params.value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) ); |
|
|
|
|
|
QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) ); |
|
|
|
|
|
// Get cached image |
|
|
QgsAccessControl *accessControl = serverIface->accessControls(); |
|
|
QgsServerCacheManager *cacheManager = serverIface->cacheManager(); |
|
|
if ( cacheManager ) |
|
|
{ |
|
|
ImageOutputFormat outputFormat = parseImageFormat( format ); |
|
|
QString saveFormat; |
|
|
QString contentType; |
|
|
switch ( outputFormat ) |
|
|
{ |
|
|
case PNG: |
|
|
case PNG8: |
|
|
case PNG16: |
|
|
case PNG1: |
|
|
contentType = "image/png"; |
|
|
saveFormat = "PNG"; |
|
|
break; |
|
|
case JPEG: |
|
|
contentType = "image/jpeg"; |
|
|
saveFormat = "JPEG"; |
|
|
break; |
|
|
default: |
|
|
throw QgsServiceException( "InvalidFormat", |
|
|
QString( "Output format '%1' is not supported in the GetLegendGraphic request" ).arg( format ) ); |
|
|
break; |
|
|
} |
|
|
|
|
|
QImage image; |
|
|
QByteArray content = cacheManager->getCachedImage( project, request, accessControl ); |
|
|
if ( !content.isEmpty() && image.loadFromData( content ) ) |
|
|
{ |
|
|
response.setHeader( QStringLiteral( "Content-Type" ), contentType ); |
|
|
image.save( response.io(), qPrintable( saveFormat ) ); |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
QgsRenderer renderer( serverIface, project, wmsParameters ); |
|
|
|
|
|
std::unique_ptr<QImage> result( renderer.getLegendGraphics() ); |
|
|
|
|
|
if ( result ) |
|
|
{ |
|
|
QString format = params.value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) ); |
|
|
writeImage( response, *result, format, renderer.getImageQuality() ); |
|
|
if ( cacheManager ) |
|
|
{ |
|
|
QByteArray content = response.data(); |
|
|
if ( !content.isEmpty() ) |
|
|
cacheManager->setCachedImage( &content, project, request, accessControl ); |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|