Skip to content

Commit

Permalink
Read queryLayers metadata for WMS data sources
Browse files Browse the repository at this point in the history
  • Loading branch information
adube committed Jan 13, 2020
1 parent e4aa5c8 commit cce8217
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
25 changes: 23 additions & 2 deletions contribs/gmf/src/datasource/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,19 +524,40 @@ export class DatasourceManager {
break;
}
}

// Read 'meta.queryLayers' for WMS data source to set 'getData'
//
// If a WMS data source has the `queryLayers` property set in
// its metadata, then it lists the layers that should be used
// when queries are issued with that data source, i.e. when a
// WFS GetFeature request is issued. The 'queryable' property
// still needs to be true for the purpose of the filter tool to
// work properly, i.e. a data source must be queryable to be
// filtrable.

const queryLayers = meta.queryLayers ? meta.queryLayers.split(',') : null;

wmsLayers = gmfLayerWMS.layers.split(',').map((childLayer) => {
return {
const item = {
name: childLayer,
queryable: queryable,
};
if (queryLayers && !queryLayers.includes(childLayer)) {
item.getData = false;
}
return item;
});
wfsLayers = gmfLayerWMS.childLayers.map((childLayer) => {
return {
const item = {
maxResolution: childLayer.maxResolutionHint,
minResolution: childLayer.minResolutionHint,
name: childLayer.name,
queryable: childLayer.queryable
};
if (queryLayers && !queryLayers.includes(childLayer.name)) {
item.getData = false;
}
return item;
});

// OGC Server
Expand Down
6 changes: 4 additions & 2 deletions contribs/gmf/src/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
/**
* Additional attributes related on a WMS layers (or WFS features type).
* @typedef {Object} GmfLayerChildLayer
* @property {boolean|undefined} [getData] If the layer is queryable and this property is set to
* false, then the layer won't be used in queries issued. Defaults to `true`.
* @property {number} maxResolutionHint The min resolution where the layer is visible.
* @property {number} minResolutionHint The max resolution where the layer is visible.
* @property {string} name
Expand Down Expand Up @@ -222,8 +224,8 @@
* WMTS layers.
* @property {string} [printLayers] A WMS layer that will be used instead of the WMTS layers in the print.
* Used to increase quality of printed WMTS layers. For WMTS layers.
* @property {string} [queryLayers] The WMS layers used as references to query the WMTS layers. For WMTS
* layers.
* @property {string} [queryLayers] The WMS layers used as references to query the WMTS layers (for WMTS
* layers) or the WFS layers that should be queried only in case of a WFS GetFeature request.
* @property {string} [thumbnail] The icon visible in the background selector. For WMS and WMTS layers.
* @property {string} [timeAttribute] The name of the time attribute. For WMS(-T) layers.
* @property {GmfSnappingConfig} [snappingConfig] The snapping configuration for the leaf. If set, the
Expand Down
38 changes: 32 additions & 6 deletions src/datasource/OGC.js
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,13 @@ class OGC extends ngeoDatasourceDataSource {

if (this.wmsLayers) {
for (const wmsLayer of this.wmsLayers) {
if (!queryableOnly || wmsLayer.queryable) {
if (
!queryableOnly ||
(
wmsLayer.queryable &&
wmsLayer.getData !== false
)
) {
layerNames.push(wmsLayer.name);
}
}
Expand Down Expand Up @@ -1043,7 +1049,16 @@ class OGC extends ngeoDatasourceDataSource {
const inMaxRange = maxRes === undefined || res <= maxRes;
const inRange = inMinRange && inMaxRange;

if (inRange && (!queryableOnly || wfsLayer.queryable)) {
if (
inRange &&
(
!queryableOnly ||
(
wfsLayer.queryable &&
wfsLayer.getData !== false
)
)
) {
layerNames.push(wfsLayer.name);
}
}
Expand All @@ -1064,7 +1079,13 @@ class OGC extends ngeoDatasourceDataSource {

if (this.wfsLayers) {
for (const wfsLayer of this.wfsLayers) {
if (!queryableOnly || wfsLayer.queryable) {
if (
!queryableOnly ||
(
wfsLayer.queryable &&
wfsLayer.getData !== false
)
) {
layerNames.push(wfsLayer.name);
}
}
Expand All @@ -1075,15 +1096,20 @@ class OGC extends ngeoDatasourceDataSource {

/**
* Returns the filtrable WFS layer name. This methods asserts that
* the name exists and is filtrable.
* the name exists and is filtrable. It also asserts that there
* should be only one layer (if it has many) that "gets data" for
* data data source.
* @return {string} WFS layer name.
*/
getFiltrableWFSLayerName() {
if (!this.filtrable) {
throw new Error('Missing filtrable');
}
const layerNames = this.getWFSLayerNames();
console.assert(layerNames.length === 1);
const layerNames = this.getWFSLayerNames(true);
console.assert(
layerNames.length === 1,
'Only one layer should be filtrable, i.e. should be able to get data.'
);
return layerNames[0];
}

Expand Down

0 comments on commit cce8217

Please sign in to comment.