Skip to content

Commit 074f982

Browse files
committed
VectorLayerUtils: filter duplicate vertices in simplifyFeature and skip features if simplification failed
1 parent ebec10f commit 074f982

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@panoramax/web-viewer": "^4.0.1",
2828
"@reduxjs/toolkit": "^2.4.0",
2929
"@turf/buffer": "^6.5.0",
30+
"@turf/clean-coords": "^7.3.1",
3031
"@turf/helpers": "^6.5.0",
3132
"@vtaits/react-color-picker": "^2.0.0",
3233
"any-date-parser": "^1.5.4",

utils/VectorLayerUtils.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9+
import cleanCords from '@turf/clean-coords';
910
import geojsonBbox from 'geojson-bounding-box';
1011
import isEmpty from 'lodash.isempty';
1112
import {getDefaultImageStyle} from 'ol/format/KML';
@@ -48,8 +49,14 @@ const VectorLayerUtils = {
4849
if (feature.geometry?.coordinates) {
4950
feature = {...feature, geometry: {...feature.geometry, coordinates: VectorLayerUtils.removeDuplicateNodes(feature.geometry.coordinates)}};
5051
}
51-
return VectorLayerUtils.simplifyFeature(feature);
52-
}).flat();
52+
try {
53+
return VectorLayerUtils.simplifyFeature(feature);
54+
} catch (e) {
55+
/* eslint-disable-next-line */
56+
console.warn("Skipping invalid geometry");
57+
return null;
58+
}
59+
}).filter(Boolean).flat();
5360
for (const feature of features) {
5461
if (!VectorLayerUtils.validateGeometry(feature.geometry)) {
5562
continue;
@@ -145,7 +152,7 @@ const VectorLayerUtils = {
145152
});
146153
}).flat();
147154
} else if (feature.geometry.type === "Polygon") {
148-
return simplepolygon(feature).features.map((feat, idx, features) => {
155+
return simplepolygon(cleanCords(feature)).features.map((feat, idx, features) => {
149156
if (feat.properties.parent >= 0) {
150157
features[feat.properties.parent].geometry.coordinates.push(feat.geometry.coordinates[0]);
151158
return null;

yarn.lock

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,16 @@
15031503
"@turf/helpers" "^6.5.0"
15041504
"@turf/meta" "^6.5.0"
15051505

1506+
1507+
version "7.3.1"
1508+
resolved "https://registry.yarnpkg.com/@turf/boolean-point-on-line/-/boolean-point-on-line-7.3.1.tgz#6742d720848ce117f48956bbaec1cfdbe6a765b2"
1509+
integrity sha512-8Hywuv7XFpSc8nfH0BJBtt+XTcJ7OjfjpX2Sz+ty8gyiY/2nCLLqq6amu3ebr67ruqZTDpPNQoGGUbUePjF3rA==
1510+
dependencies:
1511+
"@turf/helpers" "7.3.1"
1512+
"@turf/invariant" "7.3.1"
1513+
"@types/geojson" "^7946.0.10"
1514+
tslib "^2.8.1"
1515+
15061516
"@turf/buffer@^6.5.0":
15071517
version "6.5.0"
15081518
resolved "https://registry.yarnpkg.com/@turf/buffer/-/buffer-6.5.0.tgz#22bd0d05b4e1e73eaebc69b8f574a410ff704842"
@@ -1524,13 +1534,32 @@
15241534
"@turf/bbox" "^6.5.0"
15251535
"@turf/helpers" "^6.5.0"
15261536

1537+
"@turf/clean-coords@^7.3.1":
1538+
version "7.3.1"
1539+
resolved "https://registry.yarnpkg.com/@turf/clean-coords/-/clean-coords-7.3.1.tgz#555f1cc9a0822ca5c6fb5a5eaf51555c140b6961"
1540+
integrity sha512-uNo4lnTekvkw8dUCXIVCc38nZiHBrpy5jn0T8hlodZo/A4XAChFtLQi8NLcX8rtXcaNxeJo+yaPfpP3PSVI2jw==
1541+
dependencies:
1542+
"@turf/boolean-point-on-line" "7.3.1"
1543+
"@turf/helpers" "7.3.1"
1544+
"@turf/invariant" "7.3.1"
1545+
"@types/geojson" "^7946.0.10"
1546+
tslib "^2.8.1"
1547+
15271548
"@turf/clone@^6.5.0":
15281549
version "6.5.0"
15291550
resolved "https://registry.yarnpkg.com/@turf/clone/-/clone-6.5.0.tgz#895860573881ae10a02dfff95f274388b1cda51a"
15301551
integrity sha512-mzVtTFj/QycXOn6ig+annKrM6ZlimreKYz6f/GSERytOpgzodbQyOgkfwru100O1KQhhjSudKK4DsQ0oyi9cTw==
15311552
dependencies:
15321553
"@turf/helpers" "^6.5.0"
15331554

1555+
1556+
version "7.3.1"
1557+
resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-7.3.1.tgz#2f0e666ecdefbf75d0df1b94ea1f5ccc6e4abc5b"
1558+
integrity sha512-zkL34JVhi5XhsuMEO0MUTIIFEJ8yiW1InMu4hu/oRqamlY4mMoZql0viEmH6Dafh/p+zOl8OYvMJ3Vm3rFshgg==
1559+
dependencies:
1560+
"@types/geojson" "^7946.0.10"
1561+
tslib "^2.8.1"
1562+
15341563
"@turf/helpers@^4.5.0", "@turf/helpers@^4.7.3":
15351564
version "4.7.3"
15361565
resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-4.7.3.tgz#bc312ac43cab3c532a483151c4c382c5649429e9"
@@ -1548,6 +1577,15 @@
15481577
dependencies:
15491578
"@turf/invariant" "^4.7.3"
15501579

1580+
1581+
version "7.3.1"
1582+
resolved "https://registry.yarnpkg.com/@turf/invariant/-/invariant-7.3.1.tgz#9b0bb8f74af870f0b10a2e9285e62f4983f99ac2"
1583+
integrity sha512-IdZJfDjIDCLH+Gu2yLFoSM7H23sdetIo5t4ET1/25X8gi3GE2XSqbZwaGjuZgNh02nisBewLqNiJs2bo+hrqZA==
1584+
dependencies:
1585+
"@turf/helpers" "7.3.1"
1586+
"@types/geojson" "^7946.0.10"
1587+
tslib "^2.8.1"
1588+
15511589
"@turf/invariant@^4.7.3":
15521590
version "4.7.3"
15531591
resolved "https://registry.yarnpkg.com/@turf/invariant/-/invariant-4.7.3.tgz#538f367d23c113fc849d70c9a524b8563874601d"
@@ -1692,7 +1730,7 @@
16921730
dependencies:
16931731
"@types/geojson" "*"
16941732

1695-
"@types/geojson@*", "@types/geojson@^7946.0.16", "@types/geojson@^7946.0.7":
1733+
"@types/geojson@*", "@types/geojson@^7946.0.10", "@types/geojson@^7946.0.16", "@types/geojson@^7946.0.7":
16961734
version "7946.0.16"
16971735
resolved "https://registry.yarnpkg.com/@types/geojson/-/geojson-7946.0.16.tgz#8ebe53d69efada7044454e3305c19017d97ced2a"
16981736
integrity sha512-6C8nqWur3j98U6+lXDfTUWIfgvZU+EumvpHKcYjujKH7woYyLj2sUmff0tRhrqM7BohUw7Pz3ZB1jj2gW9Fvmg==
@@ -6947,7 +6985,7 @@ tslib@^1.11.1:
69476985
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
69486986
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
69496987

6950-
tslib@^2.0.0, tslib@^2.0.1, tslib@^2.0.3:
6988+
tslib@^2.0.0, tslib@^2.0.1, tslib@^2.0.3, tslib@^2.8.1:
69516989
version "2.8.1"
69526990
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f"
69536991
integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==

0 commit comments

Comments
 (0)