Skip to content

Commit c793e66

Browse files
committedJan 10, 2017
Port bugfix from PR #3906 to service
1 parent 3f41db3 commit c793e66

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed
 

‎src/server/services/wms/qgswmsservertransitional.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,26 +1592,32 @@ namespace QgsWms
15921592

15931593
//Adapt width / height if the aspect ratio does not correspond with the BBOX.
15941594
//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" ) )
15961597
{
15971598
bool bboxOk;
15981599
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+
}
15991611
if ( bboxOk )
16001612
{
16011613
double mapWidthHeightRatio = mapExtent.width() / mapExtent.height();
16021614
double imageWidthHeightRatio = ( double )width / ( double )height;
16031615
if ( !qgsDoubleNear( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
16041616
{
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;
16151621
}
16161622
}
16171623
}

0 commit comments

Comments
 (0)
Please sign in to comment.