Skip to content

Commit

Permalink
Handle dimensionsFilters in ngeo.dataSource.datacombinableWithDataSou…
Browse files Browse the repository at this point in the history
…rceForWFS
  • Loading branch information
arnaud-morvan committed Jan 27, 2020
1 parent ba665ff commit bf9f84d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
56 changes: 55 additions & 1 deletion src/datasource/OGC.js
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,8 @@ class OGC extends ngeoDatasourceDataSource {
this.supportsWFS && dataSource.supportsWFS &&
this.queryable && dataSource.queryable &&
this.wfsUrl === dataSource.wfsUrl &&
this.haveTheSameActiveDimensions(dataSource);
this.haveTheSameActiveDimensions(dataSource) &&
this.haveTheSameActiveDimensionsFilters(dataSource);
}

/**
Expand Down Expand Up @@ -1163,6 +1164,59 @@ class OGC extends ngeoDatasourceDataSource {
return share;
}

/**
* Compare active dimensions filters of two data sources. As Openlayers
* WFS format does not allow constructing multiple typenames GetFeature
* request with different filters we need to combine data sources depending
* on active dimensions filters.
* @param {!ngeox.dataSource.OGC} dataSource Remote data source to
* compare with this one.
* @return {boolean} Whether the two data sources have the same active
* dimensions filters. If both have no dimensions, they are considered
* to be sharing the same dimensions filters.
* @export
* @override
*/
haveTheSameActiveDimensionsFilters(dataSource) {
const myConfig = this.dimensionsFiltersConfig;
const itsConfig = dataSource.dimensionsFiltersConfig;
if (myConfig === null || itsConfig === null) {
return false;
}

const equals = function(key) {
const myKeyConfig = myConfig[key];
const itsKeyConfig = itsConfig[key];
if (myKeyConfig === undefined || itsKeyConfig === undefined) {
return false;
}

if (myKeyConfig.field != itsKeyConfig.field) {
return false;
}

const myValue = myKeyConfig.value !== null ? myKeyConfig.value : this.dimensions[key];
const itsValue = itsKeyConfig.value !== null ? itsKeyConfig.value : dataSource.dimensions[key];
if (myValue != itsValue) {
return false;
}

return true;
}.bind(this);

for (const key in this.dimensionsFiltersConfig) {
if (!equals(key)) {
return false;
}
}
for (const key in dataSource.dimensionsFiltersConfig) {
if (!equals(key)) {
return false;
}
}
return true;
}

// ===============================
// === Private utility methods ===
// ===============================
Expand Down
3 changes: 2 additions & 1 deletion src/query/Querent.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,8 @@ export class Querent {
).length > 0)) {

console.assert(
dataSources.length === 1,
dataSources.length === 1 ||
!(dataSource.timeRangeValue || (dataSource.filterRules && dataSource.filterRules.length)),
`A data source having filterRules or timeRangeValue should issue
a single query, alone.`
);
Expand Down

0 comments on commit bf9f84d

Please sign in to comment.