@@ -1592,26 +1592,32 @@ namespace QgsWms
1592
1592
1593
1593
// Adapt width / height if the aspect ratio does not correspond with the BBOX.
1594
1594
// Required by WMS spec. 1.3.
1595
- if ( useBbox )
1595
+ QString version = mParameters .value ( QStringLiteral ( " VERSION" ), QStringLiteral ( " 1.3.0" ) );
1596
+ if ( useBbox && version != QLatin1String ( " 1.1.1" ) )
1596
1597
{
1597
1598
bool bboxOk;
1598
1599
QgsRectangle mapExtent = _parseBBOX ( mParameters .value ( " BBOX" ), bboxOk );
1600
+ QString crs = mParameters .value ( QStringLiteral ( " CRS" ), mParameters .value ( QStringLiteral ( " SRS" ) ) );
1601
+ if ( crs.compare ( " CRS:84" , Qt::CaseInsensitive ) == 0 )
1602
+ {
1603
+ crs = QString ( " EPSG:4326" );
1604
+ mapExtent.invert ();
1605
+ }
1606
+ QgsCoordinateReferenceSystem outputCRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs ( crs );
1607
+ if ( outputCRS.hasAxisInverted () )
1608
+ {
1609
+ mapExtent.invert ();
1610
+ }
1599
1611
if ( bboxOk )
1600
1612
{
1601
1613
double mapWidthHeightRatio = mapExtent.width () / mapExtent.height ();
1602
1614
double imageWidthHeightRatio = ( double )width / ( double )height;
1603
1615
if ( !qgsDoubleNear ( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
1604
1616
{
1605
- if ( mapWidthHeightRatio >= imageWidthHeightRatio )
1606
- {
1607
- // increase image height
1608
- height = width * mapWidthHeightRatio;
1609
- }
1610
- else
1611
- {
1612
- // increase image width
1613
- width = height / mapWidthHeightRatio;
1614
- }
1617
+ // inspired by MapServer, mapdraw.c L115
1618
+ double cellsize = ( mapExtent.width () / ( double )width ) * 0.5 + ( mapExtent.height () / ( double )height ) * 0.5 ;
1619
+ width = mapExtent.width () / cellsize;
1620
+ height = mapExtent.height () / cellsize;
1615
1621
}
1616
1622
}
1617
1623
}
0 commit comments