30
30
31
31
namespace QgsWmts
32
32
{
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
+ }
33
44
34
45
/* *
35
46
* Output WMTS GetCapabilities response
@@ -312,20 +323,36 @@ namespace QgsWmts
312
323
313
324
QDomElement getContentsElement ( QDomDocument &doc, QgsServerInterface *serverIface, const QgsProject *project )
314
325
{
315
- #ifdef HAVE_SERVER_PYTHON_PLUGINS
316
- QgsAccessControl *accessControl = serverIface->accessControls ();
317
- #endif
318
326
/*
319
327
* Adding layer list in ContentMetadata
320
328
*/
321
329
QDomElement contentsElement = doc.createElement ( QStringLiteral ( " Contents" )/* wmts:Contents*/ );
322
330
323
331
QList< tileMatrixSetDef > tmsList = getTileMatrixSetList ( project );
324
332
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 )
325
350
{
326
351
QList< layerDef > wmtsLayers;
352
+ #ifdef HAVE_SERVER_PYTHON_PLUGINS
353
+ QgsAccessControl *accessControl = serverIface->accessControls ();
354
+ #endif
327
355
QgsCoordinateReferenceSystem wgs84 = QgsCoordinateReferenceSystem::fromOgcWmsCrs ( GEO_EPSG_CRS_AUTHID );
328
- QList<tileMatrixSetDef>::iterator tmsIt = tmsList.begin ();
329
356
330
357
QStringList nonIdentifiableLayers = project->nonIdentifiableLayers ();
331
358
@@ -492,8 +519,15 @@ namespace QgsWmts
492
519
493
520
wmtsLayers.append ( pLayer );
494
521
}
522
+ return wmtsLayers;
523
+ }
495
524
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
497
531
std::function < void ( QDomElement &, const QString & ) > appendInfoFormat = [&doc]( QDomElement & elem, const QString & format )
498
532
{
499
533
QDomElement formatElem = doc.createElement ( QStringLiteral ( " InfoFormat" )/* wmts:InfoFormat*/ );
@@ -544,10 +578,8 @@ namespace QgsWmts
544
578
layerElem.appendChild ( wgs84BBoxElement );
545
579
546
580
// Other bounding boxes
547
- tmsIt = tmsList.begin ();
548
- for ( ; tmsIt != tmsList.end (); ++tmsIt )
581
+ for ( tileMatrixSetDef tms : tmsList )
549
582
{
550
- tileMatrixSetDef &tms = *tmsIt;
551
583
if ( tms.ref == QLatin1String ( " EPSG:4326" ) )
552
584
continue ;
553
585
@@ -606,10 +638,8 @@ namespace QgsWmts
606
638
appendInfoFormat ( layerElem, QStringLiteral ( " application/vnd.ogc.gml/3.1.1" ) );
607
639
}
608
640
609
- tmsIt = tmsList.begin ();
610
- for ( ; tmsIt != tmsList.end (); ++tmsIt )
641
+ for ( tileMatrixSetDef tms : tmsList )
611
642
{
612
- tileMatrixSetDef &tms = *tmsIt;
613
643
if ( tms.ref != QLatin1String ( " EPSG:4326" ) )
614
644
{
615
645
QgsRectangle rect;
@@ -636,11 +666,8 @@ namespace QgsWmts
636
666
// wmts:TileMatrixSetLimits
637
667
QDomElement tmsLimitsElement = doc.createElement ( QStringLiteral ( " TileMatrixSetLimits" )/* wmts:TileMatrixSetLimits*/ );
638
668
int tmIdx = 0 ;
639
- QList<tileMatrixDef>::iterator tmIt = tms.tileMatrixList .begin ();
640
- for ( ; tmIt != tms.tileMatrixList .end (); ++tmIt )
669
+ for ( tileMatrixDef tm : tms.tileMatrixList )
641
670
{
642
- tileMatrixDef &tm = *tmIt;
643
-
644
671
QDomElement tmLimitsElement = doc.createElement ( QStringLiteral ( " TileMatrixLimits" )/* wmts:TileMatrixLimits*/ );
645
672
646
673
QDomElement tmIdentifierElem = doc.createElement ( QStringLiteral ( " TileMatrix" ) );
@@ -679,12 +706,13 @@ namespace QgsWmts
679
706
680
707
contentsElement.appendChild ( layerElem );
681
708
}
709
+ }
682
710
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 )
685
715
{
686
- tileMatrixSetDef &tms = *tmsIt;
687
-
688
716
// wmts:TileMatrixSet
689
717
QDomElement tmsElement = doc.createElement ( QStringLiteral ( " TileMatrixSet" )/* wmts:TileMatrixSet*/ );
690
718
@@ -700,11 +728,8 @@ namespace QgsWmts
700
728
701
729
// wmts:TileMatrix
702
730
int tmIdx = 0 ;
703
- QList<tileMatrixDef>::iterator tmIt = tms.tileMatrixList .begin ();
704
- for ( ; tmIt != tms.tileMatrixList .end (); ++tmIt )
731
+ for ( tileMatrixDef tm : tms.tileMatrixList )
705
732
{
706
- tileMatrixDef &tm = *tmIt;
707
-
708
733
QDomElement tmElement = doc.createElement ( QStringLiteral ( " TileMatrix" )/* wmts:TileMatrix*/ );
709
734
710
735
QDomElement tmIdentifierElem = doc.createElement ( QStringLiteral ( " ows:Identifier" ) );
@@ -750,9 +775,7 @@ namespace QgsWmts
750
775
}
751
776
}
752
777
753
- // End
754
- return contentsElement;
755
- }
778
+ } // namespace
756
779
757
780
} // namespace QgsWmts
758
781
0 commit comments