From b96d9f32f56d485d1388e1e1da014058be7d0b64 Mon Sep 17 00:00:00 2001 From: Beatrice Mkumbo Date: Thu, 17 Oct 2024 13:55:26 +0300 Subject: [PATCH] feat(web): support cesium and google photorealistic 3d tiles (#1172) Co-authored-by: airslice --- web/package.json | 2 +- .../ThreeDTiles/index.tsx | 128 +++++++++++++++--- .../Map/DataSourceLayerCreator/index.tsx | 10 +- .../InspectorPanel/LayerInspector/index.tsx | 2 + .../Editor/Map/shared/SharedComponent.tsx | 9 +- web/src/beta/features/Visualizer/index.tsx | 1 + .../lib/reearth-ui/components/Radio/index.tsx | 45 ++++-- .../components/RadioGroup/index.tsx | 8 +- web/src/services/i18n/translations/en.yml | 6 + web/src/services/i18n/translations/ja.yml | 6 + web/yarn.lock | 10 +- 11 files changed, 184 insertions(+), 43 deletions(-) diff --git a/web/package.json b/web/package.json index 433c3b504a..af9e7106f5 100644 --- a/web/package.json +++ b/web/package.json @@ -124,7 +124,7 @@ "@lexical/utils": "0.12.0", "@monaco-editor/react": "4.6.0", "@popperjs/core": "2.11.8", - "@reearth/core": "0.0.7-alpha.15", + "@reearth/core": "0.0.7-alpha.17", "@rot1024/use-transition": "1.0.0", "@sentry/browser": "7.77.0", "@seznam/compose-react-refs": "1.0.6", diff --git a/web/src/beta/features/Editor/Map/DataSourceLayerCreator/ThreeDTiles/index.tsx b/web/src/beta/features/Editor/Map/DataSourceLayerCreator/ThreeDTiles/index.tsx index 3b7a473fec..217a79c766 100644 --- a/web/src/beta/features/Editor/Map/DataSourceLayerCreator/ThreeDTiles/index.tsx +++ b/web/src/beta/features/Editor/Map/DataSourceLayerCreator/ThreeDTiles/index.tsx @@ -3,29 +3,124 @@ import { SubmitWrapper, Wrapper, InputsWrapper, - ContentWrapper + ContentWrapper, + LinkWrapper } from "@reearth/beta/features/Editor/Map/shared/SharedComponent"; -import { Button, TextInput } from "@reearth/beta/lib/reearth-ui"; +import { Button, RadioGroup, TextInput } from "@reearth/beta/lib/reearth-ui"; import { useT } from "@reearth/services/i18n"; -import { FC, useState } from "react"; +import { FC, useCallback, useMemo, useState } from "react"; -import { DataProps } from ".."; +import { DataProps, DataSourceOptType, SourceType } from ".."; import { generateTitle } from "../util"; const ThreeDTiles: FC = ({ sceneId, onSubmit, onClose }) => { const t = useT(); + const [value, setValue] = useState(""); + const [sourceType, setSourceType] = useState("osm-buildings"); + const [googleMapsApiKey, setGoogleMapsApiKey] = useState(""); + const googlePhotorealistic = sourceType === "google-photorealistic"; + + const renderGooglePhotorealisticInput = useMemo(() => { + if (googlePhotorealistic) { + return ( + + {t("Google Maps API Key ")} ( {t("You can apply a key ")} + + {t("here")} + + ) + + } + > + + setGoogleMapsApiKey(value)} + /> + + + ); + } else return undefined; + }, [googleMapsApiKey, googlePhotorealistic, t]); + + const renderUrlInput = useMemo(() => { + if (sourceType === "url") { + return ( + + + setValue(value)} + /> + + + ); + } else return undefined; + }, [sourceType, t, value]); + + const dataSourceOptions: DataSourceOptType = useMemo( + () => [ + { label: t("Cesium OSM 3D Tiles"), value: "osm-buildings" }, + { + label: t("Google Photorealistic 3D Tiles"), + value: "google-photorealistic", + children: renderGooglePhotorealisticInput + }, + { + label: t("URL"), + value: "url", + children: renderUrlInput + } + ], + [renderGooglePhotorealisticInput, renderUrlInput, t] + ); + + const handleDataSourceTypeChange = useCallback((newValue: string) => { + setSourceType(newValue as SourceType); + setValue(""); + setGoogleMapsApiKey(""); + }, []); + + const title = useMemo(() => { + if (googlePhotorealistic) { + return t("Google Photorealistic 3D Tiles"); + } else if (sourceType === "osm-buildings") { + return t("Cesium OSM 3D Tiles"); + } else { + return generateTitle(value); + } + }, [googlePhotorealistic, sourceType, t, value]); const handleSubmit = () => { onSubmit({ layerType: "simple", sceneId, - title: generateTitle(value), + title, visible: true, config: { data: { url: value !== "" ? value : undefined, - type: "3dtiles" + ...(googlePhotorealistic + ? { + serviceTokens: { + googleMapApiKey: googleMapsApiKey || undefined + } + } + : {}), + type: + sourceType === "osm-buildings" + ? "osm-buildings" + : googlePhotorealistic + ? "google-photorealistic" + : "3dtiles" } } }); @@ -35,23 +130,22 @@ const ThreeDTiles: FC = ({ sceneId, onSubmit, onClose }) => { return ( - - - setValue(value)} - /> - - + -