Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Port bugfix from PR #3906 to service
  • Loading branch information
dmarteau committed Jan 10, 2017
1 parent 3f41db3 commit c793e66
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/server/services/wms/qgswmsservertransitional.cpp
Expand Up @@ -1592,26 +1592,32 @@ namespace QgsWms

//Adapt width / height if the aspect ratio does not correspond with the BBOX.
//Required by WMS spec. 1.3.
if ( useBbox )
QString version = mParameters.value( QStringLiteral( "VERSION" ), QStringLiteral( "1.3.0" ) );
if ( useBbox && version != QLatin1String( "1.1.1" ) )
{
bool bboxOk;
QgsRectangle mapExtent = _parseBBOX( mParameters.value( "BBOX" ), bboxOk );
QString crs = mParameters.value( QStringLiteral( "CRS" ), mParameters.value( QStringLiteral( "SRS" ) ) );
if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
{
crs = QString( "EPSG:4326" );
mapExtent.invert();
}
QgsCoordinateReferenceSystem outputCRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( crs );
if ( outputCRS.hasAxisInverted() )
{
mapExtent.invert();
}
if ( bboxOk )
{
double mapWidthHeightRatio = mapExtent.width() / mapExtent.height();
double imageWidthHeightRatio = ( double )width / ( double )height;
if ( !qgsDoubleNear( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
{
if ( mapWidthHeightRatio >= imageWidthHeightRatio )
{
//increase image height
height = width * mapWidthHeightRatio;
}
else
{
//increase image width
width = height / mapWidthHeightRatio;
}
// inspired by MapServer, mapdraw.c L115
double cellsize = ( mapExtent.width() / ( double )width ) * 0.5 + ( mapExtent.height() / ( double )height ) * 0.5;
width = mapExtent.width() / cellsize;
height = mapExtent.height() / cellsize;
}
}
}
Expand Down

0 comments on commit c793e66

Please sign in to comment.