Skip to content

Commit 45cb47c

Browse files
committedAug 18, 2012
fix #5931
1 parent 24603ea commit 45cb47c

File tree

1 file changed

+47
-24
lines changed

1 file changed

+47
-24
lines changed
 

‎src/providers/wms/qgswmsprovider.cpp

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
564564
QSettings s;
565565
bool bkLayerCaching = s.value( "/qgis/enable_render_caching", false ).toBool();
566566

567-
if ( !mTiled )
567+
if ( !mTiled && !mMaxWidth && !mMaxHeight )
568568
{
569569
// Calculate active layers that are also visible.
570570

@@ -655,33 +655,53 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
655655
{
656656
mTileReqNo++;
657657

658-
Q_ASSERT( mTileLayer );
659-
Q_ASSERT( mTileMatrixSet );
660-
Q_ASSERT( mTileMatrixSet->tileMatrices.size() > 0 );
661-
662658
double vres = viewExtent.width() / pixelWidth;
663659
double tres = vres;
664660

665-
QMap<double, QgsWmtsTileMatrix> &m = mTileMatrixSet->tileMatrices;
661+
const QgsWmtsTileMatrix *tm = 0;
662+
enum QgsTileMode tileMode;
666663

667-
// find nearest resolution
668-
QMap<double, QgsWmtsTileMatrix>::const_iterator prev, it = m.constBegin();
669-
while ( it != m.constEnd() && it.key() < vres )
664+
if ( mTiled )
670665
{
671-
QgsDebugMsg( QString( "res:%1 >= %2" ).arg( it.key() ).arg( vres ) );
672-
prev = it;
673-
it++;
674-
}
666+
Q_ASSERT( mTileLayer );
667+
Q_ASSERT( mTileMatrixSet );
668+
Q_ASSERT( mTileMatrixSet->tileMatrices.size() > 0 );
675669

676-
if ( it == m.constEnd() ||
677-
( it != m.constBegin() && vres - prev.key() < it.key() - vres ) )
678-
{
679-
QgsDebugMsg( "back to previous res" );
680-
it = prev;
670+
QMap<double, QgsWmtsTileMatrix> &m = mTileMatrixSet->tileMatrices;
671+
672+
// find nearest resolution
673+
QMap<double, QgsWmtsTileMatrix>::const_iterator prev, it = m.constBegin();
674+
while ( it != m.constEnd() && it.key() < vres )
675+
{
676+
QgsDebugMsg( QString( "res:%1 >= %2" ).arg( it.key() ).arg( vres ) );
677+
prev = it;
678+
it++;
679+
}
680+
681+
if ( it == m.constEnd() ||
682+
( it != m.constBegin() && vres - prev.key() < it.key() - vres ) )
683+
{
684+
QgsDebugMsg( "back to previous res" );
685+
it = prev;
686+
}
687+
688+
tres = it.key();
689+
tm = &it.value();
690+
691+
tileMode = mTileLayer->tileMode;
681692
}
693+
else
694+
{
695+
static QgsWmtsTileMatrix tempTm;
696+
tempTm.topLeft = QgsPoint( mLayerExtent.xMinimum(), mLayerExtent.yMaximum() );
697+
tempTm.tileWidth = mMaxWidth;
698+
tempTm.tileHeight = mMaxHeight;
699+
tempTm.matrixWidth = ceil( mLayerExtent.width() / mMaxWidth / vres );
700+
tempTm.matrixHeight = ceil( mLayerExtent.height() / mMaxHeight / vres );
701+
tm = &tempTm;
682702

683-
tres = it.key();
684-
const QgsWmtsTileMatrix *tm = &it.value();
703+
tileMode = WMSC;
704+
}
685705

686706
QgsDebugMsg( QString( "layer extent: %1,%2 %3x%4" )
687707
.arg( mLayerExtent.xMinimum(), 0, 'f' )
@@ -715,7 +735,9 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
715735
int minTileRow = 0;
716736
int maxTileRow = tm->matrixHeight - 1;
717737

718-
if ( mTileLayer->setLinks.contains( mTileMatrixSet->identifier ) &&
738+
739+
if ( mTileLayer &&
740+
mTileLayer->setLinks.contains( mTileMatrixSet->identifier ) &&
719741
mTileLayer->setLinks[ mTileMatrixSet->identifier ].limits.contains( tm->identifier ) )
720742
{
721743
const QgsWmtsTileMatrixLimits &tml = mTileLayer->setLinks[ mTileMatrixSet->identifier ].limits[ tm->identifier ];
@@ -745,7 +767,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
745767
}
746768
#endif
747769

748-
switch ( mTileLayer->tileMode )
770+
switch ( tileMode )
749771
{
750772
case WMSC:
751773
{
@@ -760,7 +782,8 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
760782
setQueryItem( url, "STYLES", mActiveSubStyles.join( "," ) );
761783
setQueryItem( url, "FORMAT", mImageMimeType );
762784
setQueryItem( url, crsKey, mImageCrs );
763-
setQueryItem( url, "TILED", "true" );
785+
if ( mTiled )
786+
setQueryItem( url, "TILED", "true" );
764787

765788
int i = 0;
766789
for ( int row = row0; row <= row1; row++ )
@@ -982,7 +1005,7 @@ void QgsWmsProvider::tileReplyFinished()
9821005
cmd.setRawHeaders( hl );
9831006

9841007
QgsDebugMsg( QString( "expirationDate:%1" ).arg( cmd.expirationDate().toString() ) );
985-
if( cmd.expirationDate().isNull() )
1008+
if ( cmd.expirationDate().isNull() )
9861009
{
9871010
QSettings s;
9881011
cmd.setExpirationDate( QDateTime::currentDateTime().addSecs( s.value( "/qgis/defaultTileExpiry", "24" ).toInt() * 60 * 60 ) );

0 commit comments

Comments
 (0)
Please sign in to comment.