Skip to content

Commit

Permalink
refactor: add event listener when tileset ready
Browse files Browse the repository at this point in the history
  • Loading branch information
airslice committed Aug 8, 2023
1 parent 14645d1 commit 4976ad0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,13 @@ const convertStyle = (val: any, convert: StyleProperty["convert"]) => {
const useFeature = ({
id,
tileset,
tilesetReady,
layer,
evalFeature,
}: {
id?: string;
tileset: MutableRefObject<Cesium3DTileset | undefined>;
tilesetReady: boolean;
layer?: ComputedLayer;
evalFeature: EvalFeature;
}) => {
Expand Down Expand Up @@ -227,7 +229,7 @@ const useFeature = ({
await attachComputedFeature(feature);
});
});
}, [tileset, cachedFeaturesRef, attachComputedFeature, layerId]);
}, [tileset, tilesetReady, cachedFeaturesRef, attachComputedFeature, layerId]);

useEffect(() => {
cachedCalculatedLayerRef.current = layer;
Expand Down Expand Up @@ -378,6 +380,7 @@ export const useHooks = ({
}),
);
const tilesetRef = useRef<Cesium3DTilesetType>();
const [tilesetReady, setTilesReady] = useState(false);

const ref = useCallback(
(tileset: CesiumComponentRef<Cesium3DTilesetType> | null) => {
Expand All @@ -388,13 +391,17 @@ export const useHooks = ({
(tileset?.cesiumElement as any)[layerIdField] = layer.id;
}
tilesetRef.current = tileset?.cesiumElement;
if (tilesetRef.current) {
setTilesReady(true);
}
},
[id, layer?.id, feature?.id],
);

useFeature({
id,
tileset: tilesetRef,
tilesetReady,
layer,
evalFeature,
});
Expand Down
9 changes: 8 additions & 1 deletion web/src/classic/core/engines/Cesium/Feature/Tileset/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,13 @@ const convertStyle = (val: any, convert: StyleProperty["convert"]) => {
const useFeature = ({
id,
tileset,
tilesetReady,
layer,
evalFeature,
}: {
id?: string;
tileset: MutableRefObject<Cesium3DTileset | undefined>;
tilesetReady: boolean;
layer?: ComputedLayer;
evalFeature: EvalFeature;
}) => {
Expand Down Expand Up @@ -223,7 +225,7 @@ const useFeature = ({
await attachComputedFeature(feature);
});
});
}, [tileset, cachedFeaturesRef, attachComputedFeature, layerId]);
}, [tileset, tilesetReady, cachedFeaturesRef, attachComputedFeature, layerId]);

useEffect(() => {
cachedCalculatedLayerRef.current = layer;
Expand Down Expand Up @@ -370,6 +372,7 @@ export const useHooks = ({
}),
);
const tilesetRef = useRef<Cesium3DTilesetType>();
const [tilesetReady, setTilesReady] = useState(false);

const ref = useCallback(
(tileset: CesiumComponentRef<Cesium3DTilesetType> | null) => {
Expand All @@ -380,13 +383,17 @@ export const useHooks = ({
(tileset?.cesiumElement as any)[layerIdField] = layer.id;
}
tilesetRef.current = tileset?.cesiumElement;
if (tilesetRef.current) {
setTilesReady(true);
}
},
[id, layer?.id, feature?.id],
);

useFeature({
id,
tileset: tilesetRef,
tilesetReady,
layer,
evalFeature,
});
Expand Down

0 comments on commit 4976ad0

Please sign in to comment.