@@ -1994,26 +1994,32 @@ QImage* QgsWMSServer::createImage( int width, int height, bool useBbox ) const
1994
1994
1995
1995
// Adapt width / height if the aspect ratio does not correspond with the BBOX.
1996
1996
// Required by WMS spec. 1.3.
1997
- if ( useBbox )
1997
+ QString version = mParameters .value ( QStringLiteral ( " VERSION" ), QStringLiteral ( " 1.3.0" ) );
1998
+ if ( useBbox && version != QLatin1String ( " 1.1.1" ) )
1998
1999
{
1999
2000
bool bboxOk;
2000
2001
QgsRectangle mapExtent = _parseBBOX ( mParameters .value ( " BBOX" ), bboxOk );
2002
+ QString crs = mParameters .value ( QStringLiteral ( " CRS" ), mParameters .value ( QStringLiteral ( " SRS" ) ) );
2003
+ if ( crs.compare ( " CRS:84" , Qt::CaseInsensitive ) == 0 )
2004
+ {
2005
+ crs = QString ( " EPSG:4326" );
2006
+ mapExtent.invert ();
2007
+ }
2008
+ QgsCoordinateReferenceSystem outputCRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs ( crs );
2009
+ if ( outputCRS.hasAxisInverted () )
2010
+ {
2011
+ mapExtent.invert ();
2012
+ }
2001
2013
if ( bboxOk )
2002
2014
{
2003
2015
double mapWidthHeightRatio = mapExtent.width () / mapExtent.height ();
2004
2016
double imageWidthHeightRatio = ( double )width / ( double )height;
2005
2017
if ( !qgsDoubleNear ( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
2006
2018
{
2007
- if ( mapWidthHeightRatio >= imageWidthHeightRatio )
2008
- {
2009
- // increase image height
2010
- height = width * mapWidthHeightRatio;
2011
- }
2012
- else
2013
- {
2014
- // increase image width
2015
- width = height / mapWidthHeightRatio;
2016
- }
2019
+ // inspired by MapServer, mapdraw.c L115
2020
+ double cellsize = ( mapExtent.width () / ( double )width ) * 0.5 + ( mapExtent.height () / ( double )height ) * 0.5 ;
2021
+ width = mapExtent.width () / cellsize;
2022
+ height = mapExtent.height () / cellsize;
2017
2023
}
2018
2024
}
2019
2025
}
0 commit comments