diff --git a/src/app/core/utils/geo.js b/src/app/core/utils/geo.js index 5466a0d43..caf8f2959 100644 --- a/src/app/core/utils/geo.js +++ b/src/app/core/utils/geo.js @@ -20,53 +20,56 @@ const Geometry = { */ removeZValueToOLFeatureGeometry({feature, geometryType}={}){ const geometry = feature.getGeometry(); - geometryType = geometryType || geometry.getType(); - const originalFeatureCoordinates = geometry.getCoordinates(); - switch (geometryType){ - // POINT: [x, y] - case GeometryTypes.POINT: - if (originalFeatureCoordinates.length === 3) { - originalFeatureCoordinates.splice(2); + if (geometry) { + geometryType = geometryType || geometry.getType(); + const originalFeatureCoordinates = geometry.getCoordinates(); + switch (geometryType){ + // POINT: [x, y] + case GeometryTypes.POINT: + if (originalFeatureCoordinates.length === 3) { + originalFeatureCoordinates.splice(2); + feature.getGeometry().setCoordinates(originalFeatureCoordinates); + } + break; + // MULTIPOINT: [ [x1, y1], [x2, y2] ] + case GeometryTypes.MULTIPOINT: + // LINE: [ [x1, y1], [x2, y2] ] + case GeometryTypes.LINESTRING: + case GeometryTypes.LINE: + originalFeatureCoordinates.forEach(coordinates => coordinates.splice(2)); feature.getGeometry().setCoordinates(originalFeatureCoordinates); - } - break; - // MULTIPOINT: [ [x1, y1], [x2, y2] ] - case GeometryTypes.MULTIPOINT: - // LINE: [ [x1, y1], [x2, y2] ] - case GeometryTypes.LINESTRING: - case GeometryTypes.LINE: - originalFeatureCoordinates.forEach(coordinates => coordinates.splice(2)); - feature.getGeometry().setCoordinates(originalFeatureCoordinates); - break; - // MULTILINE: [ - // [ [x1, y1], [x2, y2] ], - // [ [x3, y3], [x4, y4] ] - // ] - case GeometryTypes.MULTILINESTRING: - case GeometryTypes.MULTILINE: - originalFeatureCoordinates.forEach(singleLine => { - singleLine.forEach(coordinates => coordinates.splice(2)) - }); - feature.getGeometry().setCoordinates(originalFeatureCoordinates); - break; - // POLYGON: [ - // [ [x1, y1], [x2, y2], [x3, y3], [x1, y1] ] - // ] - case GeometryTypes.POLYGON: - originalFeatureCoordinates[0].forEach(coordinates => coordinates.splice(2)); - feature.getGeometry().setCoordinates(originalFeatureCoordinates); - break; - // MULTIPOLYGON:[ - // [ [x1, y1], [x2, y2], [x3, y3], [x1, y1] ], - // [ [xa, ya], [xb, yb], [xc, yc], [xa, ya] ] - // ] - case GeometryTypes.MULTIPOLYGON: - originalFeatureCoordinates.forEach(singlePolygon => { - singlePolygon[0].forEach(coordinates => coordinates.splice(2)) - }); - feature.getGeometry().setCoordinates(originalFeatureCoordinates); - break; + break; + // MULTILINE: [ + // [ [x1, y1], [x2, y2] ], + // [ [x3, y3], [x4, y4] ] + // ] + case GeometryTypes.MULTILINESTRING: + case GeometryTypes.MULTILINE: + originalFeatureCoordinates.forEach(singleLine => { + singleLine.forEach(coordinates => coordinates.splice(2)) + }); + feature.getGeometry().setCoordinates(originalFeatureCoordinates); + break; + // POLYGON: [ + // [ [x1, y1], [x2, y2], [x3, y3], [x1, y1] ] + // ] + case GeometryTypes.POLYGON: + originalFeatureCoordinates[0].forEach(coordinates => coordinates.splice(2)); + feature.getGeometry().setCoordinates(originalFeatureCoordinates); + break; + // MULTIPOLYGON:[ + // [ [x1, y1], [x2, y2], [x3, y3], [x1, y1] ], + // [ [xa, ya], [xb, yb], [xc, yc], [xa, ya] ] + // ] + case GeometryTypes.MULTIPOLYGON: + originalFeatureCoordinates.forEach(singlePolygon => { + singlePolygon[0].forEach(coordinates => coordinates.splice(2)) + }); + feature.getGeometry().setCoordinates(originalFeatureCoordinates); + break; + } } + return feature; }, diff --git a/src/app/core/utils/parsers.js b/src/app/core/utils/parsers.js index 35b558165..9cdc17afc 100644 --- a/src/app/core/utils/parsers.js +++ b/src/app/core/utils/parsers.js @@ -117,7 +117,7 @@ const utils = { // Need to remove Z values due a incorrect addition when using // ol.format.WMSGetFeatureInfo readFeatures method from XML - // (eg. WMS getFeatureInfo); + // (eg. WMS getFeatureInfo); if (!is3DGeometry(geometryType)){ features.forEach(feature => removeZValueToOLFeatureGeometry({ feature, geometryType })); }