From f0fba609eb5ff412944fba2abb09f61cc9871d6c Mon Sep 17 00:00:00 2001 From: mbarto Date: Tue, 25 Oct 2016 11:46:19 +0200 Subject: [PATCH] Fixes #1182: right usage of GML2 for WFS 1.0.0 (#1203) --- web/client/utils/FilterUtils.jsx | 33 +++++--- .../utils/__tests__/FilterUtils-test.js | 76 +++++++++++++++++-- 2 files changed, 93 insertions(+), 16 deletions(-) diff --git a/web/client/utils/FilterUtils.jsx b/web/client/utils/FilterUtils.jsx index a68c4cf2a6..54d0c05b13 100644 --- a/web/client/utils/FilterUtils.jsx +++ b/web/client/utils/FilterUtils.jsx @@ -6,6 +6,19 @@ * LICENSE file in the root directory of this source tree. */ +const normalizeVersion = (version) => { + if (!version) { + return "2.0"; + } + if (version === "1.0") { + return "1.0.0"; + } + if (version === "1.1") { + return "1.1.0"; + } + return version; +}; + const FilterUtils = { ogcVersion: "2.0", ogcLogicalOperator: { @@ -43,7 +56,7 @@ const FilterUtils = { return e; } - const versionOGC = version || this.ogcVersion; + const versionOGC = normalizeVersion(version || this.ogcVersion); this.nsplaceholder = versionOGC === "2.0" ? "fes" : "ogc"; this.setOperatorsPlaceholders("{namespace}", this.nsplaceholder); @@ -129,7 +142,7 @@ const FilterUtils = { }); }, getGetFeatureBase: function(version, pagination, hits, format) { - let ver = !version ? "2.0" : version; + let ver = normalizeVersion(version); let getFeature = ' { return coordinate[0] + " " + coordinate[1]; }); - if (version === "2.0") { - gmlPoint += '' + coords.join(" ") + ''; - } else { + if (version === "1.0.0") { gmlPoint += '' + element[0][0] + '' + element[0][1] + ''; + } else { + gmlPoint += '' + coords.join(" ") + ''; } }); @@ -496,16 +509,16 @@ const FilterUtils = { // /////////////////////////////////////////////////////////////////////////////////////////////////////// coordinates.forEach((element, index) => { let coords = element.map((coordinate) => { - return coordinate[0] + (version === "2.0" ? " " : ",") + coordinate[1]; + return coordinate[0] + (version === "1.0.0" ? "," : " ") + coordinate[1]; }); - const exterior = (version === "2.0" ? "exterior" : "outerBoundaryIs"); - const interior = (version === "2.0" ? "exterior" : "innerBoundaryIs"); + const exterior = (version === "1.0.0" ? "outerBoundaryIs" : "exterior"); + const interior = (version === "1.0.0" ? "innerBoundaryIs" : "exterior"); gmlPolygon += (index < 1 ? '' : '') + '' + - (version === "2.0" ? '' : '') + + (version === "1.0.0" ? '' : '') + coords.join(" ") + - (version === "2.0" ? '' : '') + + (version === "1.0.0" ? '' : '') + '' + (index < 1 ? '' : ''); }); diff --git a/web/client/utils/__tests__/FilterUtils-test.js b/web/client/utils/__tests__/FilterUtils-test.js index 66050cb939..11d6a677b1 100644 --- a/web/client/utils/__tests__/FilterUtils-test.js +++ b/web/client/utils/__tests__/FilterUtils-test.js @@ -308,7 +308,7 @@ describe('FilterUtils', () => { let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj); expect(filter).toEqual(expected); }); - it('Check SpatialFilterField ogc 1.0 Polygon', () => { + it('Check SpatialFilterField ogc 1.0.0 Polygon', () => { let filterObj = { spatialField: { "operation": "INTERSECTS", @@ -320,11 +320,11 @@ describe('FilterUtils', () => { } } }; - let expected = 'geometry1,1 1,2 2,2 2,1 1,1'; - let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj, "1.0"); + let expected = 'geometry1,1 1,2 2,2 2,1 1,1'; + let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj, "1.0.0"); expect(filter).toEqual(expected); }); - it('Check SpatialFilterField ogc 1.0 Point', () => { + it('Check SpatialFilterField ogc 1.0.0 Point', () => { let filterObj = { spatialField: { "operation": "INTERSECTS", @@ -336,10 +336,58 @@ describe('FilterUtils', () => { } } }; - let expected = 'geometry11'; + let expected = 'geometry11'; + let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj, "1.0.0"); + expect(filter).toEqual(expected); + }); + it('Check SpatialFilterField normalizeVersion', () => { + let filterObj = { + spatialField: { + "operation": "INTERSECTS", + "attribute": "geometry", + "geometry": { + "type": "Point", + "projection": "EPSG:4326", + "coordinates": [[[1, 1]]] + } + } + }; + let expected = 'geometry11'; let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj, "1.0"); expect(filter).toEqual(expected); }); + it('Check SpatialFilterField ogc 1.1.0 Polygon', () => { + let filterObj = { + spatialField: { + "attribute": "geometry", + "operation": "INTERSECTS", + "geometry": { + "type": "Polygon", + "projection": "EPSG:4326", + "coordinates": [[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]] + } + } + }; + let expected = 'geometry1 1 1 2 2 2 2 1 1 1'; + let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj, "1.1.0"); + expect(filter).toEqual(expected); + }); + it('Check SpatialFilterField ogc 1.1.0 Point', () => { + let filterObj = { + spatialField: { + "operation": "INTERSECTS", + "attribute": "geometry", + "geometry": { + "type": "Point", + "projection": "EPSG:4326", + "coordinates": [[[1, 1]]] + } + } + }; + let expected = 'geometry1 1'; + let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj, "1.1.0"); + expect(filter).toEqual(expected); + }); it('Check SpatialFilterField ogc 2.0 Point', () => { let filterObj = { spatialField: { @@ -353,7 +401,7 @@ describe('FilterUtils', () => { } }; let expected = 'geometry1 1'; - let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj); + let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj, "2.0"); expect(filter).toEqual(expected); }); it('Check SpatialFilterField ogc 2.0 Polygon', () => { @@ -369,6 +417,22 @@ describe('FilterUtils', () => { } }; let expected = 'geometry1 1 1 2 2 2 2 1 1 1'; + let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj, "2.0"); + expect(filter).toEqual(expected); + }); + it('Check SpatialFilterField ogc default version is 2.0', () => { + let filterObj = { + spatialField: { + "operation": "INTERSECTS", + "attribute": "geometry", + "geometry": { + "type": "Point", + "projection": "EPSG:4326", + "coordinates": [[[1, 1]]] + } + } + }; + let expected = 'geometry1 1'; let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj); expect(filter).toEqual(expected); });