Skip to content

Commit

Permalink
fix: terrain isn't loaded (#669)
Browse files Browse the repository at this point in the history
  • Loading branch information
keiya01 authored Aug 9, 2024
1 parent 6e49b16 commit 57ab5ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
30 changes: 17 additions & 13 deletions src/Globe/Globe.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { action } from "@storybook/addon-actions";
import { Meta, StoryObj } from "@storybook/react";
import { CesiumTerrainProvider, IonResource } from "cesium";
import { CesiumTerrainProvider, EllipsoidTerrainProvider, IonResource } from "cesium";

import Viewer from "../Viewer";

import Globe from "./Globe";
import { StrictMode } from "react";

type Story = StoryObj<typeof Globe>;

Expand All @@ -18,26 +19,29 @@ export const Basic: Story = {
<Viewer full>
<Globe
{...args}
terrainProvider={new EllipsoidTerrainProvider()}
onImageryLayersUpdate={action("onImageryLayersUpdate")}
onTerrainProviderChange={action("onTerrainProviderChange")}
/>
</Viewer>
),
};

export const Prmise: Story = {
export const Promise: Story = {
args: { enableLighting: true },
render: args => (
<Viewer full>
<Globe
{...args}
terrainProvider={CesiumTerrainProvider.fromUrl(IonResource.fromAssetId(1), {
requestVertexNormals: true,
requestWaterMask: false,
})}
onImageryLayersUpdate={action("onImageryLayersUpdate")}
onTerrainProviderChange={action("onTerrainProviderChange")}
/>
</Viewer>
<StrictMode>
<Viewer full>
<Globe
{...args}
terrainProvider={CesiumTerrainProvider.fromUrl(IonResource.fromAssetId(1), {
requestVertexNormals: true,
requestWaterMask: false,
})}
onImageryLayersUpdate={action("onImageryLayersUpdate")}
onTerrainProviderChange={action("onTerrainProviderChange")}
/>
</Viewer>
</StrictMode>
),
};
8 changes: 2 additions & 6 deletions src/core/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export const useCesiumComponent = <Element, Props extends RootComponentInternalP
const initialProps = useRef<Props>(propsWithChildren(props));
const prevProps = useRef<Props>({} as Props);
const [mounted, setMounted] = useState(false);
const mountedRef = useRef(false);
const wrapperRef = useRef<HTMLDivElement>(null);
const stateRef = useRef<State>();
const eventManager = ctx?.[eventManagerContextKey];
Expand Down Expand Up @@ -135,7 +134,7 @@ export const useCesiumComponent = <Element, Props extends RootComponentInternalP
em.setEvents(useRootEvent ? null : element.current, props);
}

if (update && mountedRef.current) {
if (update) {
const maybePromise = update(element.current, props, prevProps.current, ctx);
if (isPromise(maybePromise)) {
await maybePromise;
Expand All @@ -146,7 +145,7 @@ export const useCesiumComponent = <Element, Props extends RootComponentInternalP
initialProps.current = props;

// Recreate cesium element when any read-only prop is updated
if (mountedRef.current && updatedReadonlyProps.length > 0) {
if (updatedReadonlyProps.length > 0) {
if (process.env.NODE_ENV !== "production") {
console.warn(
`Warning: <${name}> is recreated because following read-only props have been updated: ${updatedReadonlyProps.join(
Expand Down Expand Up @@ -255,8 +254,6 @@ export const useCesiumComponent = <Element, Props extends RootComponentInternalP
provided.current = undefined;
stateRef.current = undefined;
element.current = undefined;

mountedRef.current = false;
}, []); // eslint-disable-line react-hooks/exhaustive-deps

// To prevent re-execution by hot loader, execute only once
Expand Down Expand Up @@ -293,7 +290,6 @@ export const useCesiumComponent = <Element, Props extends RootComponentInternalP
// first time
prevProps.current = propsWC;
initialProps.current = propsWC;
mountedRef.current = true;
}
};
update();
Expand Down

0 comments on commit 57ab5ac

Please sign in to comment.