SWMMVis  6.0.0-alpha.4
Qt6/C++ GIS-based graphical user interface for the SWMMVis engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
WMTSLayer Class Reference

A map layer that fetches tiled imagery from an OGC WMTS service. More...

#include <wmtslayer.h>

Inheritance diagram for WMTSLayer:
Collaboration diagram for WMTSLayer:

Signals

void capabilitiesFetched (const WMTSServiceInfo &info)
 
void capabilitiesError (const QString &errorMessage)
 
void tilesUpdated ()
 
void activeLayerIdChanged (const QString &id)
 
void activeTileMatrixSetChanged (const QString &id)
 
void activeStyleChanged (const QString &style)
 
void imageFormatChanged (const QString &fmt)
 
void tileCacheMaxSizeChanged (int maxTiles)
 
void basemapRenderParamsChanged ()
 
- Signals inherited from OpenSWMMVisLayer
void nameChanged (const QString &newName)
 
void layerTypeChanged (OpenSWMMVisLayerType newType)
 
void visibilityChanged (bool visible)
 
void opacityChanged (double opacity)
 
void srsChanged (SpatialReferenceSystem *newSRS)
 
void extentChanged (const MapExtent &newExtent)
 
void childrenChanged ()
 
void repaintRequested ()
 
void temporalSpecChanged (const OpenSWMM::Render::TemporalSpec &spec)
 
void maskSpecChanged (const OpenSWMM::Render::MaskSpec &spec)
 
void auxStorageSpecChanged (const OpenSWMM::Render::AuxiliaryStorageSpec &spec)
 
void joinsChanged (const QVector< OpenSWMM::Render::JoinSpec > &joins)
 
void diagramSpecChanged (const OpenSWMM::Render::DiagramSpec &spec)
 
void labelConfigChanged ()
 

Public Member Functions

 WMTSLayer (const QUrl &serviceUrl, OpenSWMMVisWorkspace *parent=nullptr)
 
 ~WMTSLayer () override
 
QUrl serviceUrl () const
 
WMTSServiceInfo serviceInfo () const
 
bool capabilitiesReady () const
 
QString sourceDescription () const override
 Human-readable source of this layer: a file path, a service URL, or a description for in-memory / derived layers.
 
void fetchCapabilities ()
 Asynchronously fetches and parses the GetCapabilities document.
 
void setServiceInfo (const WMTSServiceInfo &info)
 Injects an already-fetched service info (e.g. from a connection dialog) so the layer can render immediately without a second GetCapabilities round-trip.
 
QString activeLayerId () const
 
void setActiveLayerId (const QString &id)
 
QString activeTileMatrixSet () const
 
void setActiveTileMatrixSet (const QString &id)
 
QString activeStyle () const
 
void setActiveStyle (const QString &style)
 
QString imageFormat () const
 
void setImageFormat (const QString &fmt)
 
int tileSize () const
 
int tileCacheMaxSize () const
 
void setTileCacheMaxSize (int maxTiles)
 Sets the maximum number of tiles held in the in-memory cache.
 
bool isRasterLayer () const override
 Returns true for layers that render into a raster buffer (WMS, WMTS, GISRaster) rather than populating QGraphicsItems.
 
bool isBasemapLayer () const override
 Returns true for world-spanning basemap layers (XYZ tile providers, WMS/WMTS services covering the whole world) that should NOT be included when computing the data-driven full extent.
 
void fetchCache (const MapExtent &extent, const QSize &viewportSize, const SpatialReferenceSystem *srs) override
 Triggers any asynchronous (or synchronous) tile/data fetch needed to populate this layer's internal cache for the given view state.
 
void render (QPainter *painter, const MapExtent &extent, const QSize &imageSize, const SpatialReferenceSystem *srs) override
 Renders this layer's content directly into painter.
 
void populateScene (QGraphicsScene *scene, const MapExtent &canvasExtent, const SpatialReferenceSystem *canvasSRS) override
 Creates / updates QGraphicsItems representing this layer in the scene.
 
void refreshScene (QGraphicsScene *scene, const MapExtent &canvasExtent, const SpatialReferenceSystem *canvasSRS) override
 Smart scene refresh — updates existing items instead of destroying and recreating.
 
void depopulateScene (QGraphicsScene *scene) override
 Removes all QGraphicsItems belonging to this layer from the scene.
 
void onCanvasCRSChanged (const SpatialReferenceSystem *newCanvasSRS) override
 Called when the user changes the canvas CRS so layers can pre-compute any CRS-dependent transform caches.
 
void fetchTileIfNeeded (const QString &cacheKey, const QUrl &tileUrl, const MapExtent &tileExtent, int level)
 
QUrl buildTileUrlPublic (const QString &layerId, const QString &style, const QString &tileMatrixSet, const WMTSTileMatrix &matrix, int col, int row) const
 
const WMTSTileMatrixselectTileMatrixPublic (const WMTSTileMatrixSet &tms, const MapExtent &canvasExtent, int pixelWidth) const
 
const OpenSWMM::Render::BasemapRenderParamsbasemapRenderParams () const
 
void setBasemapRenderParams (const OpenSWMM::Render::BasemapRenderParams &p)
 
- Public Member Functions inherited from TilePyramidLayer
 TilePyramidLayer (OpenSWMMVisWorkspace *parent=nullptr)
 
 ~TilePyramidLayer () override
 
- Public Member Functions inherited from OpenSWMMVisLayer
 OpenSWMMVisLayer (OpenSWMMVisWorkspace *parent)
 
 OpenSWMMVisLayer (const QString &name="Unlabeled Layer", OpenSWMMVisWorkspace *parent=nullptr)
 
virtual ~OpenSWMMVisLayer ()
 
QString layerId () const
 Returns the layer's immutable unique identifier (UUID).
 
QString name () const
 Returns the user-visible name of this layer.
 
void setName (const QString &name)
 Sets the user-visible name.
 
OpenSWMMVisLayerType layerType () const
 Returns the layer type discriminator.
 
bool isVisible () const
 Returns true when this layer should be drawn.
 
void setVisible (bool visible)
 Shows or hides this layer.
 
double opacity () const
 Returns the layer opacity in the range [0.0, 1.0]. 0.0 = fully transparent; 1.0 = fully opaque.
 
void setOpacity (double opacity)
 Sets the layer opacity. Values are clamped to [0.0, 1.0].
 
SpatialReferenceSystemsrs () const
 Returns the spatial reference system for this layer, or nullptr if the layer has no known CRS.
 
void setSRS (SpatialReferenceSystem *srs, bool ownsSRS=false)
 Sets (or replaces) the CRS for this layer.
 
QString crsDescription () const
 Returns a human-readable summary of this layer's CRS for display in the Properties window.
 
MapExtent extent () const
 Returns the layer extent in the layer's own CRS.
 
void setExtent (const MapExtent &extent)
 Sets the layer spatial extent (in the layer's CRS).
 
virtual QVector< QPair< QString, QString > > extendedMetadata () const
 Ordered key→value pairs of TYPE-SPECIFIC metadata, rendered by the Metadata tab below the common block the dialog builds itself.
 
void setViewportSize (int w, int h)
 Called by MapCanvas before refreshScene so layers can request the correct pixel dimensions for tile/image requests.
 
int viewportWidth () const
 
int viewportHeight () const
 
QVector< OpenSWMMVisLayer * > children () const
 Returns the ordered list of child layers.
 
double layerZValue () const
 Returns the z-value base assigned to this layer by the canvas. Items within the layer should use z-values relative to this.
 
virtual std::vector< std::unique_ptr< openswmmvis::ui::ILayerStyleSubject > > styleSubjects ()
 Slice U-2 — return the styleable subjects for the unified LayerStyleDialog.
 
void setLayerZValue (double z)
 Called by the canvas to set this layer's z-value band.
 
virtual OpenSWMM::Render::IFeatureRendererrenderer () const
 
virtual void setRenderer (std::unique_ptr< OpenSWMM::Render::IFeatureRenderer >)
 
virtual OpenSWMM::Render::RuleListruleList ()
 
virtual const OpenSWMM::Render::RuleListruleList () const
 
const OpenSWMM::Render::TemporalSpectemporalSpec () const
 
void setTemporalSpec (const OpenSWMM::Render::TemporalSpec &spec)
 
const OpenSWMM::Render::LabelConfiglabelConfig () const
 
virtual void setLabelConfig (const OpenSWMM::Render::LabelConfig &cfg)
 
const OpenSWMM::Render::MaskSpecmaskSpec () const
 
void setMaskSpec (const OpenSWMM::Render::MaskSpec &spec)
 
const OpenSWMM::Render::AuxiliaryStorageSpecauxStorageSpec () const
 
void setAuxStorageSpec (const OpenSWMM::Render::AuxiliaryStorageSpec &spec)
 
const QVector< OpenSWMM::Render::JoinSpec > & joins () const
 
void setJoins (const QVector< OpenSWMM::Render::JoinSpec > &joins)
 
const OpenSWMM::Render::DiagramSpecdiagramSpec () const
 
void setDiagramSpec (const OpenSWMM::Render::DiagramSpec &spec)
 
OpenSWMMVisWorkspaceworkspace () const
 
void setBasicAuth (const QString &username, const QString &password)
 Sets HTTP Basic authentication for all subsequent network requests.
 
void setHttpHeaders (const BasemapHttpHeaders &headers)
 Sets arbitrary extra HTTP headers applied to every request.
 
BasemapHttpHeaders httpHeaders () const
 

Properties

QUrl serviceUrl
 
QString activeLayerId
 
QString activeTileMatrixSet
 
QString activeStyle
 
QString imageFormat
 
int tileSize
 
int tileCacheMaxSize
 
- Properties inherited from OpenSWMMVisLayer
QString Name
 
bool Visible
 
double Opacity
 
QString LayerId
 
OpenSWMMVisLayerType LayerType
 
QVector< OpenSWMMVisLayer * > Children
 
QString CRS
 

Additional Inherited Members

- Public Types inherited from OpenSWMMVisLayer
enum  OpenSWMMVisLayerType {
  SWMMDefaultLayer = 0 ,
  SWMMModelLayer = 1 ,
  SWMMResultsLayer = 2 ,
  SWMMGISLayer = 3 ,
  SWMMVectorLayer = 4 ,
  SWMMRasterLayer = 5 ,
  SWMMImageryLayer = 6 ,
  SWMMTabularDataLayer = 7 ,
  SWMMTabularyTimeSeriesLayer = 8 ,
  SWMMSubProjectLayer = 9 ,
  SWMMWMSLayer = 10 ,
  SWMMWMTSLayer = 11 ,
  SWMM2DMeshLayer = 12 ,
  SWMM2DResultsLayer = 13 ,
  SWMMAnnotationLayer = 14 ,
  SWMMFeatureLayer = 15
}
 Discriminator for the concrete layer class. More...
 
- Protected Member Functions inherited from TilePyramidLayer
void cacheTile (const QString &key, const QImage &img, const MapExtent &extent, int level)
 Insert a produced tile (no-op for null images). extent is the tile's geographic extent in the subclass's tile CRS; level is the subclass's pyramid-level tag (metadata only — the fallback search is extent-based).
 
bool isTileCached (const QString &key) const
 True when key holds a non-null cached tile. Does not promote the entry in the LRU.
 
QImage cachedTileImage (const QString &key) const
 The cached image for key, or a null QImage.
 
void clearTiles ()
 Drop every cached tile (style / CRS / source change).
 
void setTileCacheCapacity (int maxTiles)
 
int tileCacheCapacity () const
 
bool resolveTileForDraw (const QString &key, const MapExtent &tileExtent, double maxSpanRatio, TileDraw &out) const
 Resolve the image + source sub-rect that should paint the tile key with geographic extent tileExtent.
 
- Protected Member Functions inherited from OpenSWMMVisLayer
bool addChild (OpenSWMMVisLayer *child)
 
bool removeChild (OpenSWMMVisLayer *child)
 
void setLayerType (OpenSWMMVisLayerType type)
 
- Protected Attributes inherited from OpenSWMMVisLayer
QByteArray m_authHeader
 "Basic <base64>" or empty
 
BasemapHttpHeaders m_httpHeaders
 arbitrary headers (incl. "referer")
 

Detailed Description

A map layer that fetches tiled imagery from an OGC WMTS service.

Implements the OGC Web Map Tile Service protocol using Qt's QNetworkAccessManager — no QGIS dependency.

Tiles are fetched in parallel, cached in the TilePyramidLayer base (keyed by "layerId/style/tileMatrixSet/zoom/col/row", each with its tile-CRS extent), and painted synchronously in render(); a tile still in flight paints as a sub-rect of the nearest cached coarser tile instead of a blank hole. Stale cache entries are automatically evicted when the cache exceeds its maximum size.

Supports both RESTful (KVP) and template URL tile addressing.

Constructor & Destructor Documentation

◆ WMTSLayer()

WMTSLayer::WMTSLayer ( const QUrl &  serviceUrl,
OpenSWMMVisWorkspace parent = nullptr 
)
explicit
Here is the call graph for this function:

◆ ~WMTSLayer()

WMTSLayer::~WMTSLayer ( )
override

Member Function Documentation

◆ activeLayerId()

QString WMTSLayer::activeLayerId ( ) const

◆ activeLayerIdChanged

void WMTSLayer::activeLayerIdChanged ( const QString &  id)
signal
Here is the caller graph for this function:

◆ activeStyle()

QString WMTSLayer::activeStyle ( ) const

◆ activeStyleChanged

void WMTSLayer::activeStyleChanged ( const QString &  style)
signal
Here is the caller graph for this function:

◆ activeTileMatrixSet()

QString WMTSLayer::activeTileMatrixSet ( ) const

◆ activeTileMatrixSetChanged

void WMTSLayer::activeTileMatrixSetChanged ( const QString &  id)
signal
Here is the caller graph for this function:

◆ basemapRenderParams()

const OpenSWMM::Render::BasemapRenderParams & WMTSLayer::basemapRenderParams ( ) const
inline

Slice X.22 — shared basemap render adjustments.

◆ basemapRenderParamsChanged

void WMTSLayer::basemapRenderParamsChanged ( )
signal

Slice X.22 — fired when setBasemapRenderParams() commits a new brightness / contrast / saturation / resampling tuple.

Here is the caller graph for this function:

◆ buildTileUrlPublic()

QUrl WMTSLayer::buildTileUrlPublic ( const QString &  layerId,
const QString &  style,
const QString &  tileMatrixSet,
const WMTSTileMatrix matrix,
int  col,
int  row 
) const
Here is the call graph for this function:

◆ capabilitiesError

void WMTSLayer::capabilitiesError ( const QString &  errorMessage)
signal

◆ capabilitiesFetched

void WMTSLayer::capabilitiesFetched ( const WMTSServiceInfo info)
signal
Here is the caller graph for this function:

◆ capabilitiesReady()

bool WMTSLayer::capabilitiesReady ( ) const

◆ depopulateScene()

void WMTSLayer::depopulateScene ( QGraphicsScene *  scene)
overridevirtual

Removes all QGraphicsItems belonging to this layer from the scene.

Reimplemented from OpenSWMMVisLayer.

Here is the caller graph for this function:

◆ fetchCache()

void WMTSLayer::fetchCache ( const MapExtent extent,
const QSize &  viewportSize,
const SpatialReferenceSystem srs 
)
overridevirtual

Triggers any asynchronous (or synchronous) tile/data fetch needed to populate this layer's internal cache for the given view state.

Called by MapCanvas::refreshLayerItems() for every visible raster layer BEFORE the MapRenderJob is started. This decouples tile-requesting (potentially async HTTP) from tile-drawing (synchronous, in the background render thread).

  • WMSLayer: issues a GetMap HTTP request if the cached tile is stale, then returns immediately. When the reply arrives the layer emits repaintRequested() to trigger another render pass.
  • WMTSLayer: fires fetchTileIfNeeded() for every tile that covers the current viewport; already-cached tiles are skipped.
  • GISRasterLayer: runs GDALWarp synchronously (fast for local files) if the cache is stale.

The default implementation is a no-op.

Parameters
extentVisible geographic extent in canvas-CRS coordinates.
viewportSizePixel dimensions of the viewport.
srsCanvas CRS.

Reimplemented from OpenSWMMVisLayer.

Here is the call graph for this function:

◆ fetchCapabilities()

void WMTSLayer::fetchCapabilities ( )

Asynchronously fetches and parses the GetCapabilities document.

◆ fetchTileIfNeeded()

void WMTSLayer::fetchTileIfNeeded ( const QString &  cacheKey,
const QUrl &  tileUrl,
const MapExtent tileExtent,
int  level 
)
Here is the caller graph for this function:

◆ imageFormat()

QString WMTSLayer::imageFormat ( ) const

◆ imageFormatChanged

void WMTSLayer::imageFormatChanged ( const QString &  fmt)
signal
Here is the caller graph for this function:

◆ isBasemapLayer()

bool WMTSLayer::isBasemapLayer ( ) const
inlineoverridevirtual

Returns true for world-spanning basemap layers (XYZ tile providers, WMS/WMTS services covering the whole world) that should NOT be included when computing the data-driven full extent.

MapCanvas::fullExtent() uses this to skip basemap layers so that "Zoom to Full Extent" zooms to the project's data (SWMM network, DTM, bounded WMS coverage) rather than the whole globe. Layers with a specific, bounded geographic footprint (GISRasterLayer, local WMS/WMTS with EX_GeographicBoundingBox) return false so they participate in the extent union.

Reimplemented from OpenSWMMVisLayer.

◆ isRasterLayer()

bool WMTSLayer::isRasterLayer ( ) const
inlineoverridevirtual

Returns true for layers that render into a raster buffer (WMS, WMTS, GISRaster) rather than populating QGraphicsItems.

The MapCanvas uses this to decide whether a layer participates in the background render job or in the QGraphicsScene overlay.

Reimplemented from OpenSWMMVisLayer.

◆ onCanvasCRSChanged()

void WMTSLayer::onCanvasCRSChanged ( const SpatialReferenceSystem newCanvasSRS)
overridevirtual

Called when the user changes the canvas CRS so layers can pre-compute any CRS-dependent transform caches.

Parameters
newCanvasSRSThe new canvas CRS.

Reimplemented from OpenSWMMVisLayer.

Here is the call graph for this function:

◆ populateScene()

void WMTSLayer::populateScene ( QGraphicsScene *  scene,
const MapExtent canvasExtent,
const SpatialReferenceSystem canvasSRS 
)
overridevirtual

Creates / updates QGraphicsItems representing this layer in the scene.

Derived classes override this to add their items to the scene. Items should be created in scene coordinates (= map CRS coordinates) after reprojecting from the layer's native CRS.

Called by the MapCanvas when:

  • The layer is first added.
  • The canvas CRS changes (after onCanvasCRSChanged).
  • The layer data changes (model loaded, tile fetched, etc.).
Parameters
sceneThe shared OpenSWMMVisScene to add items to.
canvasExtentVisible extent in canvas-CRS coordinates.
canvasSRSThe CRS currently used by the MapCanvas.

Implements OpenSWMMVisLayer.

Here is the call graph for this function:

◆ refreshScene()

void WMTSLayer::refreshScene ( QGraphicsScene *  scene,
const MapExtent canvasExtent,
const SpatialReferenceSystem canvasSRS 
)
overridevirtual

Smart scene refresh — updates existing items instead of destroying and recreating.

Override in subclasses to provide efficient incremental updates. The default implementation calls depopulateScene() then populateScene(), which is backward-compatible but causes flicker for raster/tile layers.

Raster/WMS layers should override to keep persistent scene items and update them in-place. Vector layers should override to skip rebuilding when only the view extent has changed (items are already in scene coords).

Reimplemented from OpenSWMMVisLayer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ render()

void WMTSLayer::render ( QPainter *  painter,
const MapExtent extent,
const QSize &  imageSize,
const SpatialReferenceSystem srs 
)
overridevirtual

Renders this layer's content directly into painter.

Called by the background MapRenderJob for raster layers. The painter is backed by a QImage of imageSize pixels spanning the geographic area described by extent in CRS srs. Pixel (0,0) maps to (extent.xMin, extent.yMax).

The default implementation is a no-op. Raster layer subclasses (WMS, WMTS, GISRaster) override this to paint their cached tile/image data without touching QGraphicsScene.

Parameters
painterTarget painter (backed by viewport-sized QImage).
extentVisible geographic extent in canvas-CRS coordinates.
imageSizePixel dimensions of the target image.
srsCanvas CRS.

Reimplemented from OpenSWMMVisLayer.

Here is the call graph for this function:

◆ selectTileMatrixPublic()

const WMTSTileMatrix * WMTSLayer::selectTileMatrixPublic ( const WMTSTileMatrixSet tms,
const MapExtent canvasExtent,
int  pixelWidth 
) const

◆ serviceInfo()

WMTSServiceInfo WMTSLayer::serviceInfo ( ) const

◆ serviceUrl()

QUrl WMTSLayer::serviceUrl ( ) const

◆ setActiveLayerId()

void WMTSLayer::setActiveLayerId ( const QString &  id)
Here is the call graph for this function:

◆ setActiveStyle()

void WMTSLayer::setActiveStyle ( const QString &  style)
Here is the call graph for this function:

◆ setActiveTileMatrixSet()

void WMTSLayer::setActiveTileMatrixSet ( const QString &  id)
Here is the call graph for this function:

◆ setBasemapRenderParams()

void WMTSLayer::setBasemapRenderParams ( const OpenSWMM::Render::BasemapRenderParams p)
Here is the call graph for this function:

◆ setImageFormat()

void WMTSLayer::setImageFormat ( const QString &  fmt)
Here is the call graph for this function:

◆ setServiceInfo()

void WMTSLayer::setServiceInfo ( const WMTSServiceInfo info)

Injects an already-fetched service info (e.g. from a connection dialog) so the layer can render immediately without a second GetCapabilities round-trip.

Sets m_capsReady = true and emits capabilitiesFetched().

Here is the call graph for this function:

◆ setTileCacheMaxSize()

void WMTSLayer::setTileCacheMaxSize ( int  maxTiles)

Sets the maximum number of tiles held in the in-memory cache.

Here is the call graph for this function:

◆ sourceDescription()

QString WMTSLayer::sourceDescription ( ) const
inlineoverridevirtual

Human-readable source of this layer: a file path, a service URL, or a description for in-memory / derived layers.

Default empty — the dialog shows "(none)". Concrete layers override to return their real origin (e.g. modelFilePath(), resultsFilePath(), serviceUrl(), or "(generated mesh)").

Reimplemented from OpenSWMMVisLayer.

◆ tileCacheMaxSize()

int WMTSLayer::tileCacheMaxSize ( ) const
Here is the call graph for this function:

◆ tileCacheMaxSizeChanged

void WMTSLayer::tileCacheMaxSizeChanged ( int  maxTiles)
signal
Here is the caller graph for this function:

◆ tileSize()

int WMTSLayer::tileSize ( ) const
inline

◆ tilesUpdated

void WMTSLayer::tilesUpdated ( )
signal

Property Documentation

◆ activeLayerId

QString WMTSLayer::activeLayerId
readwrite

◆ activeStyle

QString WMTSLayer::activeStyle
readwrite

◆ activeTileMatrixSet

QString WMTSLayer::activeTileMatrixSet
readwrite

◆ imageFormat

QString WMTSLayer::imageFormat
readwrite

◆ serviceUrl

QUrl WMTSLayer::serviceUrl
read

◆ tileCacheMaxSize

int WMTSLayer::tileCacheMaxSize
readwrite

◆ tileSize

int WMTSLayer::tileSize
read

The documentation for this class was generated from the following files: