mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Support for returning base64 coded results from GetMap and GetPrint
This commit is contained in:
parent
093d503fe0
commit
76d1f955c0
@ -98,7 +98,8 @@ void QgsHttpRequestHandler::sendGetMapResponse( const QString& service, QImage*
|
||||
{
|
||||
bool png8Bit = ( mFormat.compare( "image/png; mode=8bit", Qt::CaseInsensitive ) == 0 );
|
||||
bool png1Bit = ( mFormat.compare( "image/png; mode=1bit", Qt::CaseInsensitive ) == 0 );
|
||||
if ( mFormat != "PNG" && mFormat != "JPG" && !png8Bit && !png1Bit )
|
||||
bool isBase64 = mFormatString.endsWith( ";base64", Qt::CaseInsensitive );
|
||||
if ( mFormat != "PNG" && mFormat != "JPG" && !png8Bit && !png1Bit && !isBase64 )
|
||||
{
|
||||
QgsDebugMsg( "service exception - incorrect image format requested..." );
|
||||
sendServiceException( QgsMapServiceException( "InvalidFormat", "Output format '" + mFormat + "' is not supported in the GetMap request" ) );
|
||||
@ -129,6 +130,11 @@ void QgsHttpRequestHandler::sendGetMapResponse( const QString& service, QImage*
|
||||
img->save( &buffer, mFormat.toLocal8Bit().data(), -1 );
|
||||
}
|
||||
|
||||
if ( isBase64 )
|
||||
{
|
||||
ba = ba.toBase64();
|
||||
}
|
||||
|
||||
sendHttpResponse( &ba, formatToMimeType( mFormat ) );
|
||||
}
|
||||
}
|
||||
@ -293,6 +299,10 @@ void QgsHttpRequestHandler::sendServiceException( const QgsMapServiceException&
|
||||
|
||||
void QgsHttpRequestHandler::sendGetPrintResponse( QByteArray* ba ) const
|
||||
{
|
||||
if ( mFormatString.endsWith( ";base64", Qt::CaseInsensitive ) )
|
||||
{
|
||||
*ba = ba->toBase64();
|
||||
}
|
||||
sendHttpResponse( ba, formatToMimeType( mFormat ) );
|
||||
}
|
||||
|
||||
@ -408,17 +418,18 @@ void QgsHttpRequestHandler::requestStringToParameterMap( const QString& request,
|
||||
}
|
||||
else //capabilities format or GetMap format
|
||||
{
|
||||
QString formatString = parameters.value( "FORMAT" );
|
||||
mFormatString = parameters.value( "FORMAT" );
|
||||
QString formatString = mFormatString;
|
||||
if ( !formatString.isEmpty() )
|
||||
{
|
||||
QgsDebugMsg( QString( "formatString is: %1" ).arg( formatString ) );
|
||||
|
||||
//remove the image/ in front of the format
|
||||
if ( formatString.compare( "image/png", Qt::CaseInsensitive ) == 0 || formatString.compare( "png", Qt::CaseInsensitive ) == 0 )
|
||||
if ( formatString.contains( "image/png", Qt::CaseInsensitive ) == 0 || formatString.compare( "png", Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
formatString = "PNG";
|
||||
}
|
||||
else if ( formatString.compare( "image/jpeg", Qt::CaseInsensitive ) == 0 || formatString.compare( "image/jpg", Qt::CaseInsensitive ) == 0
|
||||
else if ( formatString.contains( "image/jpeg", Qt::CaseInsensitive ) == 0 || formatString.contains( "image/jpg", Qt::CaseInsensitive ) == 0
|
||||
|| formatString.compare( "jpg", Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
formatString = "JPG";
|
||||
@ -427,7 +438,7 @@ void QgsHttpRequestHandler::requestStringToParameterMap( const QString& request,
|
||||
{
|
||||
formatString = "SVG";
|
||||
}
|
||||
else if ( formatString.compare( "pdf", Qt::CaseInsensitive ) == 0 )
|
||||
else if ( formatString.contains( "pdf", Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
formatString = "PDF";
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ class QgsRequestHandler
|
||||
protected:
|
||||
/**This is set by the parseInput methods of the subclasses (parameter FORMAT, e.g. 'FORMAT=PNG')*/
|
||||
QString mFormat;
|
||||
QString mFormatString; //format string as it is passed in the request (with base
|
||||
QString mService;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user