diff --git a/web/client/api/WFS.js b/web/client/api/WFS.js index 155652ec9d..329f8469dc 100644 --- a/web/client/api/WFS.js +++ b/web/client/api/WFS.js @@ -48,24 +48,28 @@ export const getFeatureSimple = function(baseUrl, params) { export const getCapabilitiesURL = (url, {version = "1.1.0"} = {}) => { const parsed = urlUtil.parse(getDefaultUrl(url), true); return urlUtil.format(assign({}, parsed, { + search: undefined, // this allows to merge parameters correctly query: assign({ - service: "WFS", version, + ...parsed.query, + service: "WFS", request: "GetCapabilities" - }, parsed.query) + }) })); }; export const getFeatureURL = (url, typeName, { version = "1.1.0", ...params } = {}) => { const parsed = urlUtil.parse(getDefaultUrl(url), true); return urlUtil.format(assign({}, parsed, { + search: undefined, // this allows to merge parameters correctly query: assign({ - service: "WFS", typeName, version, + ...parsed.query, + service: "WFS", request: "GetFeature", ...params - }, parsed.query) + }) })); }; /** diff --git a/web/client/api/__tests__/WFS-test.js b/web/client/api/__tests__/WFS-test.js index 2b5145c91d..1bd1736b02 100644 --- a/web/client/api/__tests__/WFS-test.js +++ b/web/client/api/__tests__/WFS-test.js @@ -150,4 +150,16 @@ describe('Test WFS ogc API functions', () => { expect(getFeatureURL(_url).split('?')[0]).toBe(_url[0]); }); + it('getFeatureURL if it includes getCapabilites request', () => { + const _url = 'http://gs-stable.geosolutionsgroup.com:443/geoserver3/wfs?service=WFS&version=1.1.0&request=GetCapabilities'; + const featureURL = getFeatureURL(_url, "layerName"); + expect(featureURL.includes("request=GetFeature")).toBeTruthy(); + expect(featureURL.split('?')[1]).toEqual('typeName=layerName&version=1.1.0&service=WFS&request=GetFeature'); + }); + + it('getFeatureURL if it includes normal getFeature request with version different than the default one', () => { + const _url = 'http://gs-stable.geosolutionsgroup.com:443/geoserver3/wfs?service=WFS&version=1.1.1&request=GetFeature'; + const featureURL = getFeatureURL(_url, "layerName"); + expect(featureURL.split('?')[1]).toEqual('typeName=layerName&version=1.1.1&service=WFS&request=GetFeature'); + }); });