reearth / resium

React components for 🌏 Cesium
https://resium.reearth.io
MIT License
747 stars 135 forks source link

fix: terrain isn't loaded #669

Closed keiya01 closed 3 months ago

Primajin commented 3 months ago

Hey there @keiya01 - I seem to have the opposite problem: Since this change in 1.18.1 my terrain isn't loaded anymore - with 1.18.0 it still works.

https://github.com/Primajin/satellite-tracker/pull/104

It is only loaded when manually selecting the terrain after everything has been loaded - but it doesn't load by default as it did before.

MatthewHerbst commented 3 months ago

Seeing a similar issue to @Primajin where when we change the value of the terrainProvider passed to Viewer when switching between various terrain tilesets, Cesium does not update to reflect that change.

Should "terrainProvider" be included in the cesiumProps category in https://github.com/reearth/resium/blob/9c95c87859593ca76d8af981720034249aa37815/src/Viewer/Viewer.ts#L41 instead of in otherProps?

keiya01 commented 3 months ago

@Primajin Thank you. I investigated the issue, but I couldn't see it. Is this story your issue? This story toggles EllipsoidTerrainProvider and CesiumTerrainProvider. But this is still working in 1.18.1. Could you give me a more specific code if possible?

MatthewHerbst commented 3 months ago

For us, we're swapping a TerrainRgbProvider with a new TerrainRgbProvider. Our TerrainRgbProvider extends the MartiniTerrainProvider from cesium-martini.

We've resolved the issue in our code by forcing a terrain provider update when we toggle between providers:

// We load this hook in our `Viewer` component wrapper
export function useUpdateTerrainProvider(
    viewerRef: MutableRefObject<CesiumComponentRef<Viewer> | null>,
    terrainProvider: TerrainProvider,
) {
    useEffect(() => {
        if (!viewerRef.current?.cesiumElement) {
            return;
        }

        viewerRef.current.cesiumElement.terrainProvider = terrainProvider;
    }, [terrainProvider, viewerRef.current?.cesiumElement]);
}
keiya01 commented 3 months ago

@MatthewHerbst Thanks for your help. I fixed it in v1.18.2. Could you try it?

Primajin commented 3 months ago

Sorry for not responding earlier @keiya01, I can confirm that 1.18.2 works as expected again for me.

Thanks a lot for the fix 🙏🏻

pvocat commented 3 months ago

Hi,

Sorry to reopen that subject, but I have the exact same problem in 1.18.2. I've been using the terrainProviderViewModels and selectedTerrainProviderViewModel and it was working fine. Since I updated from 1.17.2 to 1.18.2, the terrain doesn't seem to load correctly. If I remove the default selectedTerrainProviderViewModel, then I can manually select my terrain and it will load, but it doesn't do that on app startup. So it looks exactly like Primajin described "It is only loaded when manually selecting the terrain after everything has been loaded - but it doesn't load by default as it did before.". I tried manually fixing the terrain by adding a terrainProvider to the viewer, but the issue persist.

Primajin commented 3 months ago

There is also an odd quirk when using a VPN (which is obviously beyond control of this project) the terrain doesn't load for me - when I deactivate it it works fine.

MatthewHerbst commented 2 months ago

Apologies for the delayed response. 1.18.2 has not resolved the issue for us.

From a React perspective, I would expect the changing the terrainProvider prop provided to Viewer to completely re-render the component. At it's most simple this could simply be destroy the Cesium instance and re-create it. More complex would be manually changing the cesiumElement.terrainProvider as I do in the hook I made to resolve this. I realize Cesium is a bit more nuanced about what a re-render actually means, but I don't think anything fancy needs to happen here. Happy to share anything that would be useful.