@@ -448,13 +448,16 @@ QImage QgsAmsProvider::draw( const QgsRectangle &viewExtent, int pixelWidth, int
448
448
double oy = origin[QStringLiteral ( " y" )].toDouble ();
449
449
450
450
// Search matching resolution (tile resolution <= targetRes)
451
- const QList<QVariant> lodEntries = tileInfo[QStringLiteral ( " lods" )].toList ();
451
+ QList<QVariant> lodEntries = tileInfo[QStringLiteral ( " lods" )].toList ();
452
452
if ( lodEntries.isEmpty () )
453
453
{
454
454
return QImage ();
455
455
}
456
+ std::sort ( lodEntries.begin (), lodEntries.end (), []( const QVariant & a, const QVariant & b )
457
+ {
458
+ return a.toMap ().value ( QStringLiteral ( " resolution" ) ).toDouble () > b.toMap ().value ( QStringLiteral ( " resolution" ) ).toDouble ();
459
+ } );
456
460
int level = 0 ;
457
- double resolution = lodEntries.front ().toMap ()[QStringLiteral ( " resolution" )].toDouble ();
458
461
int foundLevel = -1 ;
459
462
460
463
QMap< int , double > levelToResMap;
@@ -463,14 +466,22 @@ QImage QgsAmsProvider::draw( const QgsRectangle &viewExtent, int pixelWidth, int
463
466
QVariantMap lodEntryMap = lodEntry.toMap ();
464
467
465
468
level = lodEntryMap[QStringLiteral ( " level" )].toInt ();
466
- resolution = lodEntryMap[QStringLiteral ( " resolution" )].toDouble ();
469
+ double resolution = lodEntryMap[QStringLiteral ( " resolution" )].toDouble ();
467
470
levelToResMap.insert ( level, resolution );
468
471
if ( foundLevel < 0 && resolution <= 1.5 * targetRes )
469
472
{
470
473
foundLevel = level;
471
474
}
472
475
}
473
- level = foundLevel;
476
+ if ( foundLevel >= 0 )
477
+ {
478
+ level = foundLevel;
479
+ }
480
+ else
481
+ {
482
+ // just use best resolution available
483
+ level = lodEntries.constLast ().toMap ().value ( QStringLiteral ( " level" ) ).toInt ();
484
+ }
474
485
475
486
auto getRequests = [&levelToResMap, &viewExtent, tileWidth, tileHeight, ox, oy, targetRes, &dataSource]( int level, TileRequests & requests )
476
487
{
0 commit comments