From 3016a71584684ad6359bdc78adfffd0f2fd01f8c Mon Sep 17 00:00:00 2001 From: Beatrice Mkumbo Date: Thu, 7 Nov 2024 17:26:48 -0800 Subject: [PATCH] refactor(web): add layer from resource (#1212) Co-authored-by: airslice --- .../Map/DataSourceLayerCreator/CSV/index.tsx | 11 +- .../Map/DataSourceLayerCreator/CZML/hooks.tsx | 63 +++++++++ .../Map/DataSourceLayerCreator/CZML/index.tsx | 124 ++++++++++++++++++ .../{Common => GeoJSON}/hooks.tsx | 77 ++++------- .../{Common => GeoJSON}/index.tsx | 57 +++----- .../Map/DataSourceLayerCreator/KML/hooks.tsx | 63 +++++++++ .../Map/DataSourceLayerCreator/KML/index.tsx | 124 ++++++++++++++++++ .../ThreeDTiles/index.tsx | 12 +- .../Map/DataSourceLayerCreator/index.tsx | 31 +++-- .../Editor/Map/DataSourceLayerCreator/util.ts | 11 +- .../Editor/Map/shared/SharedComponent.tsx | 2 +- web/src/services/i18n/translations/en.yml | 22 ++-- web/src/services/i18n/translations/ja.yml | 24 ++-- 13 files changed, 493 insertions(+), 128 deletions(-) create mode 100644 web/src/beta/features/Editor/Map/DataSourceLayerCreator/CZML/hooks.tsx create mode 100644 web/src/beta/features/Editor/Map/DataSourceLayerCreator/CZML/index.tsx rename web/src/beta/features/Editor/Map/DataSourceLayerCreator/{Common => GeoJSON}/hooks.tsx (55%) rename web/src/beta/features/Editor/Map/DataSourceLayerCreator/{Common => GeoJSON}/index.tsx (65%) create mode 100644 web/src/beta/features/Editor/Map/DataSourceLayerCreator/KML/hooks.tsx create mode 100644 web/src/beta/features/Editor/Map/DataSourceLayerCreator/KML/index.tsx diff --git a/web/src/beta/features/Editor/Map/DataSourceLayerCreator/CSV/index.tsx b/web/src/beta/features/Editor/Map/DataSourceLayerCreator/CSV/index.tsx index 65b1fa51f4..f196e93c69 100644 --- a/web/src/beta/features/Editor/Map/DataSourceLayerCreator/CSV/index.tsx +++ b/web/src/beta/features/Editor/Map/DataSourceLayerCreator/CSV/index.tsx @@ -105,7 +105,11 @@ const CSV: FC = ({ sceneId, onSubmit, onClose }) => { )} - + {t( "Visualizer currently only supports CSV point data. Please specify the column names for latitude and longitude in your data below." @@ -157,6 +161,11 @@ const TextWrapper = styled("div")(({ theme }) => ({ fontWeight: theme.fonts.weight.regular })); +const IconWrapper = styled(Icon)(() => ({ + flexGrow: 0, + flexShrink: 0 +})); + const CoordinateWrapper = styled("div")(({ theme }) => ({ display: "flex", gap: theme.spacing.small, diff --git a/web/src/beta/features/Editor/Map/DataSourceLayerCreator/CZML/hooks.tsx b/web/src/beta/features/Editor/Map/DataSourceLayerCreator/CZML/hooks.tsx new file mode 100644 index 0000000000..8afe531911 --- /dev/null +++ b/web/src/beta/features/Editor/Map/DataSourceLayerCreator/CZML/hooks.tsx @@ -0,0 +1,63 @@ +import { useT } from "@reearth/services/i18n"; +import { useState, useMemo, useCallback } from "react"; + +import { DataProps, DataSourceOptType, SourceType } from ".."; +import { generateTitle } from "../util"; + +export default ({ sceneId, onClose, onSubmit }: DataProps) => { + const t = useT(); + + const [sourceType, setSourceType] = useState("local"); + + const [value, setValue] = useState(""); + const [layerName, setLayerName] = useState(""); + const dataSourceTypeOptions: DataSourceOptType = useMemo( + () => [ + { label: t("From Assets"), value: "local" }, + { label: t("From Web"), value: "url" }, + { label: t("From Value"), value: "value" } + ], + [t] + ); + + const handleSubmit = () => { + let encodeUrl = undefined; + + if (sourceType === "value" && value !== "") { + encodeUrl = "data:text/plain;charset=UTF-8," + encodeURIComponent(value); + } + + onSubmit({ + layerType: "simple", + sceneId, + title: generateTitle(value, layerName), + visible: true, + config: { + data: { + url: sourceType === "value" ? encodeUrl : value || undefined, + type: "czml", + } + } + }); + onClose(); + }; + + const handleValueChange = useCallback((value?: string, name?: string) => { + setValue(value || ""); + setLayerName(name || ""); + }, []); + + const handleDataSourceTypeChange = useCallback((newValue: string) => { + setSourceType(newValue as SourceType); + setValue(""); + }, []); + + return { + value, + dataSourceTypeOptions, + sourceType, + handleValueChange, + handleDataSourceTypeChange, + handleSubmit + }; +}; diff --git a/web/src/beta/features/Editor/Map/DataSourceLayerCreator/CZML/index.tsx b/web/src/beta/features/Editor/Map/DataSourceLayerCreator/CZML/index.tsx new file mode 100644 index 0000000000..f278c174cf --- /dev/null +++ b/web/src/beta/features/Editor/Map/DataSourceLayerCreator/CZML/index.tsx @@ -0,0 +1,124 @@ +import { + InputGroup, + SubmitWrapper, + Wrapper, + InputsWrapper, + ContentWrapper +} from "@reearth/beta/features/Editor/Map/shared/SharedComponent"; +import { + RadioGroup, + Button, + TextInput, + TextArea, + Icon +} from "@reearth/beta/lib/reearth-ui"; +import { AssetField } from "@reearth/beta/ui/fields"; +import { useT } from "@reearth/services/i18n"; +import { styled, useTheme } from "@reearth/services/theme"; +import { FC } from "react"; + +import { DataProps } from ".."; + +import useHooks from "./hooks"; + +const CZML: FC = ({ sceneId, onSubmit, onClose }) => { + const t = useT(); + + const { + value, + sourceType, + dataSourceTypeOptions, + handleValueChange, + handleDataSourceTypeChange, + handleSubmit + } = useHooks({ sceneId, onSubmit, onClose }); + + const theme = useTheme(); + return ( + + + + + + {t( + "Support for the CZML format is currently experimental and remains somewhat unstable, with certain features not yet fully supported. We advise using it with caution." + )} + + + + + + + {sourceType === "local" && ( + + + + )} + {sourceType === "url" && ( + + + + + + )} + {sourceType === "value" && ( + + +