Skip to content

Commit

Permalink
fix: 修复 geojson 数据校验错误的问题 (#47)
Browse files Browse the repository at this point in the history
* fix: 修复geojson数据校验错误的问题

* fix: 过滤掉右手报错原则

---------

Co-authored-by: syb01094648 <[email protected]>
  • Loading branch information
websybin and syb01094648 authored Mar 8, 2024
1 parent 0401f71 commit 94540c1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion src/components/app-header/btn/import-btn/file-upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const FileUpload = forwardRef<any>(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;
Expand Down
15 changes: 13 additions & 2 deletions src/pages/components/editor.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -55,8 +57,17 @@ export const Editor: React.FC<EditorProps> = (props) => {
)) as string | null;
if (newEditorText && scene && !props.features) {
try {
const newFeatures = JSON.parse(newEditorText).features;
bboxAutoFit(newFeatures);
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 {
const newFeatures = JSON.parse(newEditorText).features;
bboxAutoFit(newFeatures);
}
} catch (error) {
message.error(t('import_btn.file_upload.qingJianChaShuJu'));
}
Expand Down
27 changes: 18 additions & 9 deletions src/recoil/feature.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -71,15 +73,22 @@ 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)).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 {
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) {
message.warning(t('recoil.feature.shuJuJiaZaiYou'));
}
} catch (error) {}
} else {
setEditorText(emptyFeatures);
setSavedText(emptyFeatures);
Expand Down Expand Up @@ -195,4 +204,4 @@ export default function useFeature() {
transformCoord,
revertCoord,
};
}
}

0 comments on commit 94540c1

Please sign in to comment.