@@ -622,7 +622,10 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, in
622
622
QImage *image = new QImage ( pixelWidth, pixelHeight, QImage::Format_ARGB32 );
623
623
image->fill ( 0 );
624
624
625
- if ( !mSettings .mTiled && mSettings .mMaxWidth == 0 && mSettings .mMaxHeight == 0 )
625
+ int maxWidth = mCaps .mCapabilities .service .maxWidth == 0 ? std::numeric_limits<int >::max () : mCaps .mCapabilities .service .maxWidth ;
626
+ int maxHeight = mCaps .mCapabilities .service .maxHeight == 0 ? std::numeric_limits<int >::max () : mCaps .mCapabilities .service .maxHeight ;
627
+
628
+ if ( !mSettings .mTiled && mSettings .mMaxWidth == 0 && mSettings .mMaxHeight == 0 && pixelWidth <= maxWidth && pixelHeight <= maxHeight )
626
629
{
627
630
QUrl url = createRequestUrlWMS ( viewExtent, pixelWidth, pixelHeight );
628
631
@@ -655,16 +658,19 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, in
655
658
656
659
tileMode = mTileLayer ->tileMode ;
657
660
}
658
- else if ( mSettings .mMaxWidth != 0 && mSettings .mMaxHeight != 0 )
661
+ else if ( ( mSettings .mMaxWidth != 0 && mSettings .mMaxHeight != 0 ) || pixelWidth > maxWidth || pixelHeight > maxHeight )
659
662
{
663
+ int w = mSettings .mMaxWidth != 0 && mSettings .mMaxWidth < maxWidth ? mSettings .mMaxWidth : maxWidth;
664
+ int h = mSettings .mMaxHeight != 0 && mSettings .mMaxHeight < maxHeight ? mSettings .mMaxHeight : maxHeight;
665
+
660
666
// this is an ordinary WMS server, but the user requested tiled approach
661
667
// so we will pretend it is a WMS-C server with just one tile matrix
662
668
tempTm.reset ( new QgsWmtsTileMatrix );
663
669
tempTm->topLeft = QgsPointXY ( mLayerExtent .xMinimum (), mLayerExtent .yMaximum () );
664
- tempTm->tileWidth = mSettings . mMaxWidth ;
665
- tempTm->tileHeight = mSettings . mMaxHeight ;
666
- tempTm->matrixWidth = std::ceil ( mLayerExtent .width () / mSettings . mMaxWidth / vres );
667
- tempTm->matrixHeight = std::ceil ( mLayerExtent .height () / mSettings . mMaxHeight / vres );
670
+ tempTm->tileWidth = w ;
671
+ tempTm->tileHeight = h ;
672
+ tempTm->matrixWidth = std::ceil ( mLayerExtent .width () / w / vres );
673
+ tempTm->matrixHeight = std::ceil ( mLayerExtent .height () / h / vres );
668
674
tempTm->tres = vres;
669
675
tm = tempTm.get ();
670
676
0 commit comments