Skip to content

Commit

Permalink
Fix unhandled error on query response when `QGIS Project setting -> A…
Browse files Browse the repository at this point in the history
…dd geometry to feature response` is set to false (#173)

* Check if feature has geometry otherwise get an error removeZValueToOLFeatureGeometry function

Co-authored-by: Raruto <[email protected]>
  • Loading branch information
volterra79 and Raruto authored Sep 9, 2022
1 parent b072d23 commit 6b49021
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 46 deletions.
93 changes: 48 additions & 45 deletions src/app/core/utils/geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},

Expand Down
2 changes: 1 addition & 1 deletion src/app/core/utils/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
}
Expand Down

0 comments on commit 6b49021

Please sign in to comment.