Skip to content
Permalink
Browse files

Add support for displaying WMTS legend graphics in layer tree

  • Loading branch information
manisandro authored and nyalldawson committed Dec 4, 2019
1 parent 8410ea7 commit 7b916aaf70016e875d4053207d0afb75144aeb77
Showing with 45 additions and 0 deletions.
  1. +14 −0 src/providers/wms/qgswmscapabilities.cpp
  2. +31 −0 src/providers/wms/qgswmsprovider.cpp
@@ -1569,6 +1569,20 @@ void QgsWmsCapabilities::parseWMTSContents( const QDomElement &element )

style.legendURLs << legendURL;
}
QDomElement thirdChildElement = secondChildElement.firstChildElement( QStringLiteral( "LegendURL" ) );
if ( !thirdChildElement.isNull() )
{
QgsWmtsLegendURL legendURL;

legendURL.format = thirdChildElement.attribute( QStringLiteral( "format" ) );
legendURL.minScale = thirdChildElement.attribute( QStringLiteral( "minScaleDenominator" ) ).toDouble();
legendURL.maxScale = thirdChildElement.attribute( QStringLiteral( "maxScaleDenominator" ) ).toDouble();
legendURL.href = thirdChildElement.attribute( QStringLiteral( "xlink:href" ) );
legendURL.width = thirdChildElement.attribute( QStringLiteral( "width" ) ).toInt();
legendURL.height = thirdChildElement.attribute( QStringLiteral( "height" ) ).toInt();

style.legendURLs << legendURL;
}

style.isDefault = secondChildElement.attribute( QStringLiteral( "isDefault" ) ) == QLatin1String( "true" );

@@ -303,6 +303,31 @@ QString QgsWmsProvider::getLegendGraphicUrl() const
url = mCaps.mCapabilities.capability.request.getLegendGraphic.dcpType.front().http.get.onlineResource.xlinkHref;
}

if ( url.isEmpty() )
{
for ( const QgsWmtsTileLayer &l : mCaps.mTileLayersSupported )
{
if ( l.identifier != mSettings.mActiveSubLayers[0] )
continue;

QHash<QString, QgsWmtsStyle>::const_iterator it = l.styles.constFind( mSettings.mActiveSubStyles[0] );
if ( it == l.styles.constEnd() )
if ( it == l.styles.end() )
continue;

for ( const QgsWmtsLegendURL &u : it.value().legendURLs )
{
if ( u.format == mSettings.mImageMimeType )
url = u.href;
}
if ( url.isEmpty() && !it.value().legendURLs.isEmpty() )
url = it.value().legendURLs.front().href;

if ( !url.isEmpty() )
break;
}
}

return url.isEmpty() ? url : prepareUri( url );
}

@@ -3382,6 +3407,12 @@ QUrl QgsWmsProvider::getLegendGraphicFullURL( double scale, const QgsRectangle &

QUrl url( lurl );

if ( dataSourceUri().contains( "SERVICE=WMTS" ) || dataSourceUri().contains( "/WMTSCapabilities.xml" ) )
{
QgsDebugMsg( QString( "getlegendgraphicrequest: %1" ).arg( url.toString() ) );
return url;
}

// query names are NOT case-sensitive, so make an uppercase list for proper comparison
QStringList qnames = QStringList();
for ( int i = 0; i < url.queryItems().size(); i++ )

0 comments on commit 7b916aa

Please sign in to comment.
You can’t perform that action at this time.