Skip to content

Assign Cesium3DTileset url property at runtimeΒ #694

@hretief

Description

@hretief

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>
    </>
);

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions