@@ -566,9 +566,9 @@ QImage *QgsWmsProvider::draw( QgsRectangle const & viewExtent, int pixelWidth, i
566
566
mTileReqNo ++;
567
567
568
568
double vres = viewExtent.width () / pixelWidth;
569
- double tres = vres;
570
569
571
570
const QgsWmtsTileMatrix *tm = nullptr ;
571
+ QScopedPointer<QgsWmtsTileMatrix> tempTm;
572
572
enum QgsTileMode tileMode;
573
573
574
574
if ( mSettings .mTiled )
@@ -577,38 +577,22 @@ QImage *QgsWmsProvider::draw( QgsRectangle const & viewExtent, int pixelWidth, i
577
577
Q_ASSERT ( mTileMatrixSet );
578
578
Q_ASSERT ( !mTileMatrixSet ->tileMatrices .isEmpty () );
579
579
580
- QMap<double , QgsWmtsTileMatrix> &m = mTileMatrixSet ->tileMatrices ;
581
-
582
580
// find nearest resolution
583
- QMap<double , QgsWmtsTileMatrix>::const_iterator prev, it = m.constBegin ();
584
- while ( it != m.constEnd () && it.key () < vres )
585
- {
586
- QgsDebugMsg ( QString ( " res:%1 >= %2" ).arg ( it.key () ).arg ( vres ) );
587
- prev = it;
588
- ++it;
589
- }
590
-
591
- if ( it == m.constEnd () ||
592
- ( it != m.constBegin () && vres - prev.key () < it.key () - vres ) )
593
- {
594
- QgsDebugMsg ( " back to previous res" );
595
- it = prev;
596
- }
597
-
598
- tres = it.key ();
599
- tm = &it.value ();
581
+ tm = mTileMatrixSet ->findNearestResolution ( vres );
582
+ Q_ASSERT ( tm );
600
583
601
584
tileMode = mTileLayer ->tileMode ;
602
585
}
603
586
else if ( mSettings .mMaxWidth != 0 && mSettings .mMaxHeight != 0 )
604
587
{
605
- static QgsWmtsTileMatrix tempTm;
606
- tempTm.topLeft = QgsPoint ( mLayerExtent .xMinimum (), mLayerExtent .yMaximum () );
607
- tempTm.tileWidth = mSettings .mMaxWidth ;
608
- tempTm.tileHeight = mSettings .mMaxHeight ;
609
- tempTm.matrixWidth = ceil ( mLayerExtent .width () / mSettings .mMaxWidth / vres );
610
- tempTm.matrixHeight = ceil ( mLayerExtent .height () / mSettings .mMaxHeight / vres );
611
- tm = &tempTm;
588
+ tempTm.reset ( new QgsWmtsTileMatrix );
589
+ tempTm->topLeft = QgsPoint ( mLayerExtent .xMinimum (), mLayerExtent .yMaximum () );
590
+ tempTm->tileWidth = mSettings .mMaxWidth ;
591
+ tempTm->tileHeight = mSettings .mMaxHeight ;
592
+ tempTm->matrixWidth = ceil ( mLayerExtent .width () / mSettings .mMaxWidth / vres );
593
+ tempTm->matrixHeight = ceil ( mLayerExtent .height () / mSettings .mMaxHeight / vres );
594
+ tempTm->tres = vres;
595
+ tm = tempTm.data ();
612
596
613
597
tileMode = WMSC;
614
598
}
@@ -634,43 +618,24 @@ QImage *QgsWmsProvider::draw( QgsRectangle const & viewExtent, int pixelWidth, i
634
618
);
635
619
636
620
QgsDebugMsg ( QString ( " tile matrix %1,%2 res:%3 tilesize:%4x%5 matrixsize:%6x%7 id:%8" )
637
- .arg ( tm ->topLeft .x () ).arg ( tm ->topLeft .y () ).arg ( tres )
621
+ .arg ( tm ->topLeft .x () ).arg ( tm ->topLeft .y () ).arg ( tm -> tres )
638
622
.arg ( tm ->tileWidth ).arg ( tm ->tileHeight )
639
623
.arg ( tm ->matrixWidth ).arg ( tm ->matrixHeight )
640
624
.arg ( tm ->identifier )
641
625
);
642
626
643
- // calculate tile coordinates
644
- double twMap = tm ->tileWidth * tres;
645
- double thMap = tm ->tileHeight * tres;
646
- QgsDebugMsg ( QString ( " tile map size: %1,%2" ).arg ( qgsDoubleToString ( twMap ), qgsDoubleToString ( thMap ) ) );
647
-
648
- int minTileCol = 0 ;
649
- int maxTileCol = tm ->matrixWidth - 1 ;
650
- int minTileRow = 0 ;
651
- int maxTileRow = tm ->matrixHeight - 1 ;
652
-
627
+ const QgsWmtsTileMatrixLimits *tml = nullptr ;
653
628
654
629
if ( mTileLayer &&
655
630
mTileLayer ->setLinks .contains ( mTileMatrixSet ->identifier ) &&
656
631
mTileLayer ->setLinks [ mTileMatrixSet ->identifier ].limits .contains ( tm ->identifier ) )
657
632
{
658
- const QgsWmtsTileMatrixLimits &tml = mTileLayer ->setLinks [ mTileMatrixSet ->identifier ].limits [ tm ->identifier ];
659
- minTileCol = tml.minTileCol ;
660
- maxTileCol = tml.maxTileCol ;
661
- minTileRow = tml.minTileRow ;
662
- maxTileRow = tml.maxTileRow ;
663
- QgsDebugMsg ( QString ( " %1 %2: TileMatrixLimits col %3-%4 row %5-%6" )
664
- .arg ( mTileMatrixSet ->identifier ,
665
- tm ->identifier )
666
- .arg ( minTileCol ).arg ( maxTileCol )
667
- .arg ( minTileRow ).arg ( maxTileRow ) );
633
+ tml = &mTileLayer ->setLinks [ mTileMatrixSet ->identifier ].limits [ tm ->identifier ];
668
634
}
669
635
670
- int col0 = qBound ( minTileCol, ( int ) floor (( viewExtent.xMinimum () - tm ->topLeft .x () ) / twMap ), maxTileCol );
671
- int row0 = qBound ( minTileRow, ( int ) floor (( tm ->topLeft .y () - viewExtent.yMaximum () ) / thMap ), maxTileRow );
672
- int col1 = qBound ( minTileCol, ( int ) floor (( viewExtent.xMaximum () - tm ->topLeft .x () ) / twMap ), maxTileCol );
673
- int row1 = qBound ( minTileRow, ( int ) floor (( tm ->topLeft .y () - viewExtent.yMinimum () ) / thMap ), maxTileRow );
636
+ // calculate tile coordinates
637
+ int col0, col1, row0, row1;
638
+ tm ->viewExtentIntersection ( viewExtent, tml, col0, row0, col1, row1 );
674
639
675
640
#if QGISDEBUG
676
641
int n = ( col1 - col0 + 1 ) * ( row1 - row0 + 1 );
@@ -728,17 +693,17 @@ QImage *QgsWmsProvider::draw( QgsRectangle const & viewExtent, int pixelWidth, i
728
693
{
729
694
for ( int col = col0; col <= col1; col++ )
730
695
{
696
+ QgsRectangle bbox ( tm ->tileBBox ( col, row ) );
731
697
QString turl;
732
698
turl += url.toString ();
733
699
turl += QString ( changeXY ? " &BBOX=%2,%1,%4,%3" : " &BBOX=%1,%2,%3,%4" )
734
- .arg ( qgsDoubleToString ( tm -> topLeft . x () + col * twMap /* + twMap * 0.001 */ ),
735
- qgsDoubleToString ( tm -> topLeft . y () - ( row + 1 ) * thMap /* - thMap * 0.001 */ ),
736
- qgsDoubleToString ( tm -> topLeft . x () + ( col + 1 ) * twMap /* - twMap * 0.001 */ ),
737
- qgsDoubleToString ( tm -> topLeft . y () - row * thMap /* + thMap * 0.001 */ ) );
700
+ .arg ( qgsDoubleToString ( bbox. xMinimum () ),
701
+ qgsDoubleToString ( bbox. yMinimum () ),
702
+ qgsDoubleToString ( bbox. xMaximum () ),
703
+ qgsDoubleToString ( bbox. yMaximum () ) );
738
704
739
705
QgsDebugMsg ( QString ( " tileRequest %1 %2/%3 (%4,%5): %6" ).arg ( mTileReqNo ).arg ( i++ ).arg ( n ).arg ( row ).arg ( col ).arg ( turl ) );
740
- QRectF rect ( tm ->topLeft .x () + col * twMap, tm ->topLeft .y () - ( row + 1 ) * thMap, twMap, thMap );
741
- requests << QgsWmsTiledImageDownloadHandler::TileRequest ( turl, rect, i );
706
+ requests << QgsWmsTiledImageDownloadHandler::TileRequest ( turl, tm ->tileRect ( col, row ), i );
742
707
}
743
708
}
744
709
}
@@ -779,8 +744,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const & viewExtent, int pixelWidth, i
779
744
turl += QString ( " &TILEROW=%1&TILECOL=%2" ).arg ( row ).arg ( col );
780
745
781
746
QgsDebugMsg ( QString ( " tileRequest %1 %2/%3 (%4,%5): %6" ).arg ( mTileReqNo ).arg ( i++ ).arg ( n ).arg ( row ).arg ( col ).arg ( turl ) );
782
- QRectF rect ( tm ->topLeft .x () + col * twMap, tm ->topLeft .y () - ( row + 1 ) * thMap, twMap, thMap );
783
- requests << QgsWmsTiledImageDownloadHandler::TileRequest ( turl, rect, i );
747
+ requests << QgsWmsTiledImageDownloadHandler::TileRequest ( turl, tm ->tileRect ( col, row ), i );
784
748
}
785
749
}
786
750
}
@@ -810,8 +774,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const & viewExtent, int pixelWidth, i
810
774
811
775
if ( feedback && !feedback->preview_only )
812
776
QgsDebugMsg ( QString ( " tileRequest %1 %2/%3 (%4,%5): %6" ).arg ( mTileReqNo ).arg ( i++ ).arg ( n ).arg ( row ).arg ( col ).arg ( turl ) );
813
- QRectF rect ( tm ->topLeft .x () + col * twMap, tm ->topLeft .y () - ( row + 1 ) * thMap, twMap, thMap );
814
- requests << QgsWmsTiledImageDownloadHandler::TileRequest ( turl, rect, i );
777
+ requests << QgsWmsTiledImageDownloadHandler::TileRequest ( turl, tm ->tileRect ( col, row ), i );
815
778
}
816
779
}
817
780
}
0 commit comments