@@ -1974,26 +1974,32 @@ QImage* QgsWmsServer::createImage( int width, int height, bool useBbox ) const
1974
1974
1975
1975
// Adapt width / height if the aspect ratio does not correspond with the BBOX.
1976
1976
// Required by WMS spec. 1.3.
1977
- if ( useBbox )
1977
+ QString version = mParameters .value ( QStringLiteral ( " VERSION" ), QStringLiteral ( " 1.3.0" ) );
1978
+ if ( useBbox && version != QLatin1String ( " 1.1.1" ) )
1978
1979
{
1979
1980
bool bboxOk;
1980
1981
QgsRectangle mapExtent = _parseBBOX ( mParameters .value ( " BBOX" ), bboxOk );
1982
+ QString crs = mParameters .value ( QStringLiteral ( " CRS" ), mParameters .value ( QStringLiteral ( " SRS" ) ) );
1983
+ if ( crs.compare ( " CRS:84" , Qt::CaseInsensitive ) == 0 )
1984
+ {
1985
+ crs = QString ( " EPSG:4326" );
1986
+ mapExtent.invert ();
1987
+ }
1988
+ QgsCoordinateReferenceSystem outputCRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs ( crs );
1989
+ if ( outputCRS.hasAxisInverted () )
1990
+ {
1991
+ mapExtent.invert ();
1992
+ }
1981
1993
if ( bboxOk )
1982
1994
{
1983
1995
double mapWidthHeightRatio = mapExtent.width () / mapExtent.height ();
1984
1996
double imageWidthHeightRatio = ( double )width / ( double )height;
1985
1997
if ( !qgsDoubleNear ( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
1986
1998
{
1987
- if ( mapWidthHeightRatio >= imageWidthHeightRatio )
1988
- {
1989
- // increase image height
1990
- height = width * mapWidthHeightRatio;
1991
- }
1992
- else
1993
- {
1994
- // increase image width
1995
- width = height / mapWidthHeightRatio;
1996
- }
1999
+ // inspired by MapServer, mapdraw.c L115
2000
+ double cellsize = ( mapExtent.width () / ( double )width ) * 0.5 + ( mapExtent.height () / ( double )height ) * 0.5 ;
2001
+ width = mapExtent.width () / cellsize;
2002
+ height = mapExtent.height () / cellsize;
1997
2003
}
1998
2004
}
1999
2005
}
0 commit comments