Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate WMS query results #5283

Merged
merged 3 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {includes as olArrayIncludes} from 'ol/array.js';


/**
* Push an object in an array, unless already there.
* @param {Array.<*>} arr The array to push the element.
* @param {*} obj The object for which to test.
* @return {boolean} The object has been pushed in the array.
*/
export function pushUnlessIncluded(arr, obj) {
let ret = false;
if (!olArrayIncludes(arr, obj)) {
arr.push(obj);
ret = true;
}
return ret;
}
45 changes: 24 additions & 21 deletions src/datasource/OGC.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {pushUnlessIncluded} from 'ngeo/array.js';
import ngeoDatasourceDataSource from 'ngeo/datasource/DataSource.js';
import ngeoFilterCondition from 'ngeo/filter/Condition.js';
import ngeoFormatArcGISGeoJSON from 'ngeo/format/ArcGISGeoJSON.js';
Expand Down Expand Up @@ -470,31 +471,33 @@ class OGC extends ngeoDatasourceDataSource {

// === Calculated properties ===

// Get queryable ogc layer names
const wfsLayers = [];
if (this.queryable && this.wfsLayers) {
for (const wfsLayer of this.wfsLayers) {
// Get queryable ogc layer names.
//
// Note: for wms layer names, both wms and wfs layers are used,
// because wms can use layer group. When reading the features
// returned by wms queries, the layer "name" is used in each
// feature, not the "group". WFS does not use "group".
const wfsLayerNames = [];
const wmsLayerNames = [];
if (this.queryable) {
const wfsLayers = /** @type {WFSLayer[]} */ (this.wfsLayers || []);
for (const wfsLayer of wfsLayers) {
if (wfsLayer.queryable) {
wfsLayers.push(wfsLayer.name);
// WFS layer named is pushed in both wfs and wms lists
wfsLayerNames.push(wfsLayer.name);
wmsLayerNames.push(wfsLayer.name);
}
}
}
const wmsLayers = [];
if (this.queryable) {
for (const wmsLayer of (this.wmsLayers || [])) {
const wmsLayers = /** @type {WMSLayer[]} */ (this.wmsLayers || []);
for (const wmsLayer of wmsLayers) {
if (wmsLayer.queryable) {
wmsLayers.push(wmsLayer.name);
}
}
for (const wfsLayer of this.wfsLayers || []) {
if (wfsLayer.queryable) {
wmsLayers.push(wfsLayer.name);
pushUnlessIncluded(wmsLayerNames, wmsLayer.name);
}
}
}

let wfsFormat = null;
if (this.supportsWFS && wfsLayers.length) {
if (this.supportsWFS && wfsLayerNames.length) {
let format;
if (this.wfsOutputFormat_ === WFSOutputFormat.GML3) {
format = new olFormatGML3();
Expand All @@ -505,7 +508,7 @@ class OGC extends ngeoDatasourceDataSource {
}
wfsFormat = new olFormatWFS({
featureNS: this.wfsFeatureNS,
featureType: wfsLayers,
featureType: wfsLayerNames,
gmlFormat: format
});
}
Expand All @@ -517,15 +520,15 @@ class OGC extends ngeoDatasourceDataSource {
this.wfsFormat_ = wfsFormat;

let wmsFormat = null;
if (this.supportsWMS && wmsLayers.length) {
if (this.supportsWMS && wmsLayerNames.length) {
if (this.wmsInfoFormat === WMSInfoFormat.GML) {
wmsFormat = new olFormatWMSGetFeatureInfo({
layers: wmsLayers
layers: wmsLayerNames
});
} else if (this.wmsInfoFormat === WMSInfoFormat.GEOJSON) {
if (this.ogcServerType_ === ServerType.ARCGIS) {
wmsFormat = new ngeoFormatArcGISGeoJSON({
layers: wmsLayers
layers: wmsLayerNames
});
}
}
Expand Down Expand Up @@ -652,7 +655,7 @@ class OGC extends ngeoDatasourceDataSource {
}

/**
* @return {?Array<WFSLayer>} TFS layers
* @return {?Array<WFSLayer>} WFS layers
*/
get wfsLayers() {
return this.wfsLayers_;
Expand Down