@reearth/core 0.0.7-alpha.43 → 0.0.7-alpha.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reearth/core",
3
- "version": "0.0.7-alpha.43",
3
+ "version": "0.0.7-alpha.44",
4
4
  "author": "Re:Earth contributors <community@reearth.io>",
5
5
  "license": "Apache-2.0",
6
6
  "description": "A library that abstracts a map engine as one common API.",
@@ -82,7 +82,7 @@ export default function useHooks(
82
82
  info: SelectedFeatureInfo | undefined,
83
83
  ) => {
84
84
  const isSketchLayer =
85
- selectedLayer.layer?.layer.type === "simple" &&
85
+ selectedLayer.layer?.layer?.type === "simple" &&
86
86
  selectedLayer.layer?.layer?.data?.isSketchLayer;
87
87
  // Sketch layer feature has a fixed featureId, we need to exclude it from the skip condition
88
88
  if (
@@ -177,7 +177,7 @@ const convertStyle = (val: any, convert: StyleProperty["convert"]) => {
177
177
 
178
178
  const useFeature = ({
179
179
  id,
180
- tileset,
180
+ tilesetRef,
181
181
  idProperty,
182
182
  layer,
183
183
  viewer,
@@ -189,7 +189,7 @@ const useFeature = ({
189
189
  isTilesetReady,
190
190
  }: {
191
191
  id?: string;
192
- tileset: MutableRefObject<Cesium3DTileset | undefined>;
192
+ tilesetRef: MutableRefObject<Cesium3DTileset | undefined>;
193
193
  idProperty?: string;
194
194
  layer?: ComputedLayer;
195
195
  viewer?: Viewer;
@@ -327,10 +327,10 @@ const useFeature = ({
327
327
  handleTilesetLoadRef.current = handleTilesetLoad;
328
328
  useEffect(
329
329
  () =>
330
- tileset.current?.tileLoad.addEventListener((t: Cesium3DTile) =>
330
+ tilesetRef.current?.tileLoad.addEventListener((t: Cesium3DTile) =>
331
331
  handleTilesetLoadRef.current(t),
332
332
  ),
333
- [tileset, isTilesetReady],
333
+ [tilesetRef, isTilesetReady],
334
334
  );
335
335
 
336
336
  const handleTilesetUnload = useCallback(
@@ -346,10 +346,10 @@ const useFeature = ({
346
346
  handleTilesetUnloadRef.current = handleTilesetUnload;
347
347
  useEffect(
348
348
  () =>
349
- tileset.current?.tileUnload.addEventListener((t: Cesium3DTile) =>
349
+ tilesetRef.current?.tileUnload.addEventListener((t: Cesium3DTile) =>
350
350
  handleTilesetUnloadRef.current(t),
351
351
  ),
352
- [tileset, isTilesetReady],
352
+ [tilesetRef, isTilesetReady],
353
353
  );
354
354
 
355
355
  useEffect(() => {
@@ -487,6 +487,8 @@ export const useHooks = ({
487
487
  const shouldUseFeatureIndex = !disableIndexingFeature && !!idProperty;
488
488
 
489
489
  const [isTilesetReady, setIsTilesetReady] = useState(false);
490
+ const [isTilesetCompReady, setIsTilesetCompReady] = useState(false);
491
+ const [isTilesetRefReady, setIsTilesetRefReady] = useState(false);
490
492
 
491
493
  const prevPlanes = useRef(_planes);
492
494
  const planes = useMemo(() => {
@@ -566,6 +568,7 @@ export const useHooks = ({
566
568
  (tileset?.cesiumElement as any)[layerIdField] = layer.id;
567
569
  }
568
570
  tilesetRef.current = tileset?.cesiumElement;
571
+ setIsTilesetRefReady(!!tileset?.cesiumElement);
569
572
  },
570
573
  [id, layer?.id, featureIndex, shouldUseFeatureIndex],
571
574
  );
@@ -602,7 +605,7 @@ export const useHooks = ({
602
605
 
603
606
  useFeature({
604
607
  id,
605
- tileset: tilesetRef,
608
+ tilesetRef,
606
609
  layer,
607
610
  idProperty,
608
611
  viewer,
@@ -806,13 +809,18 @@ export const useHooks = ({
806
809
 
807
810
  const handleReady = useCallback(
808
811
  (tileset: Cesium3DTileset) => {
809
- setIsTilesetReady(true);
812
+ setIsTilesetCompReady(true);
810
813
  onLayerFetch?.({ properties: tileset.properties });
811
814
  onLayerLoad?.({ layerId: layerIdRef.current });
812
815
  },
813
816
  [onLayerFetch, onLayerLoad],
814
817
  );
815
818
 
819
+ useEffect(() => {
820
+ if (!isTilesetCompReady || !isTilesetRefReady) return;
821
+ setIsTilesetReady(true);
822
+ }, [isTilesetCompReady, isTilesetRefReady]);
823
+
816
824
  useEffect(() => {
817
825
  updateCredits?.();
818
826
  return () => {