From 19f4a914c22eaea9942947eff98a4f911e46fa71 Mon Sep 17 00:00:00 2001 From: syb01094648 Date: Fri, 12 Jan 2024 11:13:35 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dgeojson=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=A0=A1=E9=AA=8C=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + .../app-header/btn/import-btn/file-upload.tsx | 1 - src/pages/components/editor.tsx | 11 ++++++++-- src/recoil/feature.ts | 21 ++++++++++++------- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 4ad586a..de952ca 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "@antv/larkmap": "^1.4.4", "@antv/sam": "^0.1.0", "@emotion/css": "^11.11.2", + "@mapbox/geojsonhint": "^3.3.0", "@mapbox/togeojson": "^0.16.0", "@turf/turf": "^6.5.0", "ahooks": "^3.7.0", diff --git a/src/components/app-header/btn/import-btn/file-upload.tsx b/src/components/app-header/btn/import-btn/file-upload.tsx index e1c63e5..ec8de2e 100644 --- a/src/components/app-header/btn/import-btn/file-upload.tsx +++ b/src/components/app-header/btn/import-btn/file-upload.tsx @@ -34,7 +34,6 @@ const FileUpload = forwardRef(function FileUpload({}, ref) { const { file, onSuccess, onError } = uploadRequestOption; parserFileToSource(file, t) .then((dataSource) => { - console.log(dataSource); if (!dataSource?.columns) { if (dataSource.data?.features?.length) { const newData = uploadData; diff --git a/src/pages/components/editor.tsx b/src/pages/components/editor.tsx index d198fa8..01f5eab 100644 --- a/src/pages/components/editor.tsx +++ b/src/pages/components/editor.tsx @@ -1,3 +1,5 @@ +//@ts-ignore +import { hint } from '@mapbox/geojsonhint'; import { useAsyncEffect, useUpdateEffect } from 'ahooks'; import { ConfigProvider, theme as antdTheme, message } from 'antd'; import classNames from 'classnames'; @@ -55,8 +57,13 @@ export const Editor: React.FC = (props) => { )) as string | null; if (newEditorText && scene && !props.features) { try { - const newFeatures = JSON.parse(newEditorText).features; - bboxAutoFit(newFeatures); + const errors = hint(JSON.parse(newEditorText)); + if (errors.length > 0) { + message.error(t('import_btn.file_upload.qingJianChaShuJu')); + } else { + const newFeatures = JSON.parse(newEditorText).features; + bboxAutoFit(newFeatures); + } } catch (error) { message.error(t('import_btn.file_upload.qingJianChaShuJu')); } diff --git a/src/recoil/feature.ts b/src/recoil/feature.ts index dd0d7c0..9667c37 100644 --- a/src/recoil/feature.ts +++ b/src/recoil/feature.ts @@ -1,3 +1,5 @@ +//@ts-ignore +import { hint } from '@mapbox/geojsonhint'; import type { Feature } from '@turf/turf'; import { bbox, featureCollection, getType } from '@turf/turf'; import { message } from 'antd'; @@ -71,13 +73,18 @@ export default function useFeature() { let newFeatures: Feature[] = []; if (editorText || value) { try { - newFeatures = transformFeatures(value ?? editorText, t); - if (value) { - setEditorText(value); + const errors = hint(JSON.parse(value ?? editorText)); + if (errors.length > 0) { + message.warning(t('recoil.feature.shuJuJiaZaiYou')); + } else { + newFeatures = transformFeatures(value ?? editorText, t); + if (value) { + setEditorText(value); + } + setSavedText(value ?? editorText); + setFeatures(newFeatures as IFeatures); } - setSavedText(value ?? editorText); - setFeatures(newFeatures as IFeatures); - } catch (e) { + } catch (error) { message.warning(t('recoil.feature.shuJuJiaZaiYou')); } } else { @@ -195,4 +202,4 @@ export default function useFeature() { transformCoord, revertCoord, }; -} \ No newline at end of file +} From 921113c63da31864759ab87c6b83b2cdc51a1cb4 Mon Sep 17 00:00:00 2001 From: syb01094648 Date: Fri, 12 Jan 2024 11:30:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E8=BF=87=E6=BB=A4=E6=8E=89=E5=8F=B3?= =?UTF-8?q?=E6=89=8B=E6=8A=A5=E9=94=99=E5=8E=9F=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/components/editor.tsx | 6 +++++- src/recoil/feature.ts | 10 ++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/pages/components/editor.tsx b/src/pages/components/editor.tsx index 01f5eab..5d66184 100644 --- a/src/pages/components/editor.tsx +++ b/src/pages/components/editor.tsx @@ -57,7 +57,11 @@ export const Editor: React.FC = (props) => { )) as string | null; if (newEditorText && scene && !props.features) { try { - const errors = hint(JSON.parse(newEditorText)); + const errors = hint(JSON.parse(newEditorText)).filter( + (item: { message: string }) => + item.message !== + 'Polygons and MultiPolygons should follow the right-hand rule', + ); if (errors.length > 0) { message.error(t('import_btn.file_upload.qingJianChaShuJu')); } else { diff --git a/src/recoil/feature.ts b/src/recoil/feature.ts index 9667c37..19db9d7 100644 --- a/src/recoil/feature.ts +++ b/src/recoil/feature.ts @@ -73,7 +73,11 @@ export default function useFeature() { let newFeatures: Feature[] = []; if (editorText || value) { try { - const errors = hint(JSON.parse(value ?? editorText)); + const errors = hint(JSON.parse(value ?? editorText)).filter( + (item: { message: string }) => + item.message !== + 'Polygons and MultiPolygons should follow the right-hand rule', + ); if (errors.length > 0) { message.warning(t('recoil.feature.shuJuJiaZaiYou')); } else { @@ -84,9 +88,7 @@ export default function useFeature() { setSavedText(value ?? editorText); setFeatures(newFeatures as IFeatures); } - } catch (error) { - message.warning(t('recoil.feature.shuJuJiaZaiYou')); - } + } catch (error) {} } else { setEditorText(emptyFeatures); setSavedText(emptyFeatures);