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

Assign Cesium3DTileset url property at runtime #694

Open
hretief opened this issue Feb 9, 2025 · 0 comments
Open

Assign Cesium3DTileset url property at runtime #694

hretief opened this issue Feb 9, 2025 · 0 comments

Comments

@hretief
Copy link

hretief commented Feb 9, 2025

I may be missing something but for the life of me I'm unable to assign the url property at runtime. I mean there are no errors thrown, but the url property remains null . The only time it works is when I assign a default value to the ref.

Do you have an example where the url property is assigned through a prop or queried at run time and the assigned to the Cesium3DTileset component?

here is an example that works only when the ref has an initial value (and that only value ever used even if I update the ref:

interface IModelProps {
token: string;
imodelId: string;
position: Cartesian3;
name: string;
description: string;
}

export default function CADModel(props: IModelProps) {
const refUrl = useRef(STATION_URI);

useEffect(() => {
    const fetchUrl = async () => {
        try {
            console.log(`Token: ${props.token}`);
            ITwinPlatform.defaultAccessToken = props.token;
            const mytiles = await ITwinData.createTilesetFromIModelId(props.imodelId);

            refUrl.current = mytiles!.resource!.url! as string;
            console.log(`URL to the tileset: ${refUrl.current}`);
        } catch (e) {
            console.log(`Error reported while processing iModel ${props.imodelId} from Components/CADModel Component: ${e}`);
        }
    };
    fetchUrl();
}, []);

return (
    <>
        <Entity point={{ pixelSize: 20 }} name={props.name} description={props.description} position={props.position} />
        <Cesium3DTileset
            url={refUrl.current}
        ></Cesium3DTileset>
    </>
);

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant