Skip to content

Commit a53717c

Browse files
committed
[Server][Feature][needs-docs] Enhancing WMTS GetCapabilities code
1 parent 408484d commit a53717c

File tree

1 file changed

+49
-26
lines changed

1 file changed

+49
-26
lines changed

src/server/services/wmts/qgswmtsgetcapabilities.cpp

+49-26
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@
3030

3131
namespace QgsWmts
3232
{
33+
namespace
34+
{
35+
QList< layerDef > getWmtsLayerList( QgsServerInterface *serverIface, const QgsProject *project );
36+
37+
void appendLayerElements( QDomDocument &doc, QDomElement &contentsElement,
38+
QList< layerDef > wmtsLayers, QList< tileMatrixSetDef > tmsList,
39+
const QgsProject *project );
40+
41+
void appendTileMatrixSetElements( QDomDocument &doc, QDomElement &contentsElement,
42+
QList< tileMatrixSetDef > tmsList );
43+
}
3344

3445
/**
3546
* Output WMTS GetCapabilities response
@@ -312,20 +323,36 @@ namespace QgsWmts
312323

313324
QDomElement getContentsElement( QDomDocument &doc, QgsServerInterface *serverIface, const QgsProject *project )
314325
{
315-
#ifdef HAVE_SERVER_PYTHON_PLUGINS
316-
QgsAccessControl *accessControl = serverIface->accessControls();
317-
#endif
318326
/*
319327
* Adding layer list in ContentMetadata
320328
*/
321329
QDomElement contentsElement = doc.createElement( QStringLiteral( "Contents" )/*wmts:Contents*/ );
322330

323331
QList< tileMatrixSetDef > tmsList = getTileMatrixSetList( project );
324332
if ( !tmsList.isEmpty() )
333+
{
334+
// get layer list
335+
QList< layerDef > wmtsLayers = getWmtsLayerList( serverIface, project );
336+
if ( !wmtsLayers.isEmpty() )
337+
{
338+
appendLayerElements( doc, contentsElement, wmtsLayers, tmsList, project );
339+
}
340+
341+
appendTileMatrixSetElements( doc, contentsElement, tmsList );
342+
}
343+
344+
//End
345+
return contentsElement;
346+
}
347+
namespace
348+
{
349+
QList< layerDef > getWmtsLayerList( QgsServerInterface *serverIface, const QgsProject *project )
325350
{
326351
QList< layerDef > wmtsLayers;
352+
#ifdef HAVE_SERVER_PYTHON_PLUGINS
353+
QgsAccessControl *accessControl = serverIface->accessControls();
354+
#endif
327355
QgsCoordinateReferenceSystem wgs84 = QgsCoordinateReferenceSystem::fromOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
328-
QList<tileMatrixSetDef>::iterator tmsIt = tmsList.begin();
329356

330357
QStringList nonIdentifiableLayers = project->nonIdentifiableLayers();
331358

@@ -492,8 +519,15 @@ namespace QgsWmts
492519

493520
wmtsLayers.append( pLayer );
494521
}
522+
return wmtsLayers;
523+
}
495524

496-
// Append InfoFormat helper
525+
void appendLayerElements( QDomDocument &doc, QDomElement &contentsElement,
526+
QList< layerDef > wmtsLayers, QList< tileMatrixSetDef > tmsList,
527+
const QgsProject *project )
528+
{
529+
QgsCoordinateReferenceSystem wgs84 = QgsCoordinateReferenceSystem::fromOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
530+
// Define InfoFormat helper
497531
std::function < void ( QDomElement &, const QString & ) > appendInfoFormat = [&doc]( QDomElement & elem, const QString & format )
498532
{
499533
QDomElement formatElem = doc.createElement( QStringLiteral( "InfoFormat" )/*wmts:InfoFormat*/ );
@@ -544,10 +578,8 @@ namespace QgsWmts
544578
layerElem.appendChild( wgs84BBoxElement );
545579

546580
// Other bounding boxes
547-
tmsIt = tmsList.begin();
548-
for ( ; tmsIt != tmsList.end(); ++tmsIt )
581+
for ( tileMatrixSetDef tms : tmsList )
549582
{
550-
tileMatrixSetDef &tms = *tmsIt;
551583
if ( tms.ref == QLatin1String( "EPSG:4326" ) )
552584
continue;
553585

@@ -606,10 +638,8 @@ namespace QgsWmts
606638
appendInfoFormat( layerElem, QStringLiteral( "application/vnd.ogc.gml/3.1.1" ) );
607639
}
608640

609-
tmsIt = tmsList.begin();
610-
for ( ; tmsIt != tmsList.end(); ++tmsIt )
641+
for ( tileMatrixSetDef tms : tmsList )
611642
{
612-
tileMatrixSetDef &tms = *tmsIt;
613643
if ( tms.ref != QLatin1String( "EPSG:4326" ) )
614644
{
615645
QgsRectangle rect;
@@ -636,11 +666,8 @@ namespace QgsWmts
636666
//wmts:TileMatrixSetLimits
637667
QDomElement tmsLimitsElement = doc.createElement( QStringLiteral( "TileMatrixSetLimits" )/*wmts:TileMatrixSetLimits*/ );
638668
int tmIdx = 0;
639-
QList<tileMatrixDef>::iterator tmIt = tms.tileMatrixList.begin();
640-
for ( ; tmIt != tms.tileMatrixList.end(); ++tmIt )
669+
for ( tileMatrixDef tm : tms.tileMatrixList )
641670
{
642-
tileMatrixDef &tm = *tmIt;
643-
644671
QDomElement tmLimitsElement = doc.createElement( QStringLiteral( "TileMatrixLimits" )/*wmts:TileMatrixLimits*/ );
645672

646673
QDomElement tmIdentifierElem = doc.createElement( QStringLiteral( "TileMatrix" ) );
@@ -679,12 +706,13 @@ namespace QgsWmts
679706

680707
contentsElement.appendChild( layerElem );
681708
}
709+
}
682710

683-
tmsIt = tmsList.begin();
684-
for ( ; tmsIt != tmsList.end(); ++tmsIt )
711+
void appendTileMatrixSetElements( QDomDocument &doc, QDomElement &contentsElement,
712+
QList< tileMatrixSetDef > tmsList )
713+
{
714+
for ( tileMatrixSetDef tms : tmsList )
685715
{
686-
tileMatrixSetDef &tms = *tmsIt;
687-
688716
//wmts:TileMatrixSet
689717
QDomElement tmsElement = doc.createElement( QStringLiteral( "TileMatrixSet" )/*wmts:TileMatrixSet*/ );
690718

@@ -700,11 +728,8 @@ namespace QgsWmts
700728

701729
//wmts:TileMatrix
702730
int tmIdx = 0;
703-
QList<tileMatrixDef>::iterator tmIt = tms.tileMatrixList.begin();
704-
for ( ; tmIt != tms.tileMatrixList.end(); ++tmIt )
731+
for ( tileMatrixDef tm : tms.tileMatrixList )
705732
{
706-
tileMatrixDef &tm = *tmIt;
707-
708733
QDomElement tmElement = doc.createElement( QStringLiteral( "TileMatrix" )/*wmts:TileMatrix*/ );
709734

710735
QDomElement tmIdentifierElem = doc.createElement( QStringLiteral( "ows:Identifier" ) );
@@ -750,9 +775,7 @@ namespace QgsWmts
750775
}
751776
}
752777

753-
//End
754-
return contentsElement;
755-
}
778+
} // namespace
756779

757780
} // namespace QgsWmts
758781

0 commit comments

Comments
 (0)