diff --git a/src/components/ThreeDTilesLayer/ThreeDTilesLayer_1.tsx b/src/components/ThreeDTilesLayer/ThreeDTilesLayer_1.tsx new file mode 100644 index 0000000..d8e71d5 --- /dev/null +++ b/src/components/ThreeDTilesLayer/ThreeDTilesLayer_1.tsx @@ -0,0 +1,16 @@ +import Ml3DTileLayer from "../../lib/MlTile3DLayer/Ml3DTilesLayer"; + +type Props = {}; + +export default function ThreeDTilesLayer({}: Props) { + return ( + <> + + + ); +} diff --git a/src/components/ThreeDTilesLayer/ThreeDTilesLayer_2.tsx b/src/components/ThreeDTilesLayer/ThreeDTilesLayer_2.tsx new file mode 100644 index 0000000..b2fd595 --- /dev/null +++ b/src/components/ThreeDTilesLayer/ThreeDTilesLayer_2.tsx @@ -0,0 +1,36 @@ +import { useCallback, useRef } from "react"; +import Ml3DTileLayer from "../../lib/MlTile3DLayer/Ml3DTilesLayer"; +import type { Tile3D } from "@loaders.gl/tiles"; +import type { Color } from "@deck.gl/core"; + +type Props = {}; + +export default function ThreeDTilesLayer({}: Props) { + const selectedRef = useRef(null); + + const getFeatureColor = useCallback( + (featureId: number, tile: Tile3D): Color => { + const props = tile.content?.propertyTable?.[featureId]; + const surface = (props?.surface as string)?.toLowerCase(); + + if (surface === "roof") { + return [255, 80, 80]; + } + return [235, 235, 235]; + }, + [], + ); + + return ( + <> + [0,200,0]} + //getFeatureColor={getFeatureColor} + beforeId="waterway-name" + /> + + ); +} diff --git a/src/components/ThreeDTilesLayer/ThreeDTilesLayer_3.tsx b/src/components/ThreeDTilesLayer/ThreeDTilesLayer_3.tsx new file mode 100644 index 0000000..0a0e811 --- /dev/null +++ b/src/components/ThreeDTilesLayer/ThreeDTilesLayer_3.tsx @@ -0,0 +1,57 @@ +import { useCallback, useRef, useState } from "react"; +import { Enhanced3DTilePickingInfo } from "../../lib/MlTile3DLayer/Tiles3DLayer2"; +import Ml3DTileLayer from "../../lib/MlTile3DLayer/Ml3DTilesLayer"; +import type { Tile3D } from "@loaders.gl/tiles"; +import type { Color } from "@deck.gl/core"; + +type Props = {}; + +export default function ThreeDTilesLayer({}: Props) { + const [colorVersion, setColorVersion] = useState(0); + const selectedRef = useRef(null); + + const getFeatureColor = useCallback( + (featureId: number, tile: Tile3D): Color => { + const props = tile.content?.propertyTable?.[featureId]; + const gmlId = props?.gml_id as string | undefined; + const surface = (props?.surface as string)?.toLowerCase(); + + if (selectedRef.current && gmlId === selectedRef.current) { + return [0, 200, 0]; + } + if (surface === "roof") { + return [255, 80, 80]; + } + return [235, 235, 235]; + }, + [], + ); + + const onClick = useCallback((info: unknown) => { + const pickInfo = info as Enhanced3DTilePickingInfo; + if (!pickInfo.picked) return; + + const gmlId = pickInfo.featureProperties?.gml_id as string | undefined; + if (gmlId) { + const isDeselect = selectedRef.current === gmlId; + selectedRef.current = isDeselect ? null : gmlId; + setColorVersion((v) => v + 1); + } + }, []); + + return ( + <> + console.log(info)} + updateTrigger={colorVersion} + beforeId="waterway-name" + /> + + ); +} diff --git a/src/components/ThreeDTilesLayer/ThreeDTilesLayer_final.tsx b/src/components/ThreeDTilesLayer/ThreeDTilesLayer_final.tsx new file mode 100644 index 0000000..9488a96 --- /dev/null +++ b/src/components/ThreeDTilesLayer/ThreeDTilesLayer_final.tsx @@ -0,0 +1,107 @@ +import { useCallback, useRef, useState } from "react"; +import { Enhanced3DTilePickingInfo } from "../../lib/MlTile3DLayer/Tiles3DLayer2"; +import Ml3DTileLayer from "../../lib/MlTile3DLayer/Ml3DTilesLayer"; +import type { Tile3D } from "@loaders.gl/tiles"; +import type { Color } from "@deck.gl/core"; +import Box from "@mui/material/Box"; +import Typography from "@mui/material/Typography"; +import Divider from "@mui/material/Divider"; +import Paper from "@mui/material/Paper"; + +type Props = {}; + +export default function ThreeDTilesLayer({}: Props) { + const [colorVersion, setColorVersion] = useState(0); + const selectedRef = useRef(null); + const [selectedProps, setSelectedProps] = useState | null>(null); + + const getFeatureColor = useCallback( + (featureId: number, tile: Tile3D): Color => { + const props = tile.content?.propertyTable?.[featureId]; + const gmlId = props?.gml_id as string | undefined; + const surface = (props?.surface as string)?.toLowerCase(); + + if (selectedRef.current && gmlId === selectedRef.current) { + return [0, 200, 0]; + } + if (surface === "roof") { + return [255, 80, 80]; + } + return [235, 235, 235]; + }, + [], + ); + + const onClick = useCallback((info: unknown) => { + const pickInfo = info as Enhanced3DTilePickingInfo; + if (!pickInfo.picked) return; + + const gmlId = pickInfo.featureProperties?.gml_id as string | undefined; + if (gmlId) { + const isDeselect = selectedRef.current === gmlId; + selectedRef.current = isDeselect ? null : gmlId; + setSelectedProps( + isDeselect ? null : (pickInfo.featureProperties ?? null), + ); + setColorVersion((v) => v + 1); + } + }, []); + + return ( + <> + + + {selectedProps && ( + + + + Selected Building + + + + + {Object.entries(selectedProps).map(([key, value]) => ( + + + {key} + + + {String(value)} + + + ))} + + + )} + + ); +}