Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复 geojson 数据校验错误的问题 #47

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
};
}
}
Loading