@reearth/core 0.0.7-alpha.18 → 0.0.7-alpha.19
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/dist/core.js +3834 -3803
- package/dist/core.umd.cjs +42 -42
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/Map/ref.ts +1 -0
- package/src/Map/types/index.ts +1 -0
- package/src/engines/Cesium/Feature/Tileset/hooks.ts +8 -1
- package/src/engines/Cesium/Feature/context.ts +1 -0
- package/src/engines/Cesium/common.ts +34 -0
- package/src/engines/Cesium/hooks/useEngineRef.ts +6 -0
- package/src/engines/Cesium/hooks.ts +27 -39
package/dist/index.d.ts
CHANGED
|
@@ -608,6 +608,7 @@ export declare type EngineRef = {
|
|
|
608
608
|
unselectFeatures: (layerId: string, featureId: string[]) => void;
|
|
609
609
|
pickManyFromViewport: (windowPosition: [x: number, y: number], windowWidth: number, windowHeight: number, condition?: (f: PickedFeature) => boolean) => PickedFeature[] | undefined;
|
|
610
610
|
calcRectangleControlPoint: (p1: Position3d, p2: Position3d, p3: Position3d) => [p1: Position3d, p2: Position3d, p3: Position3d];
|
|
611
|
+
getCredits: () => Credit[] | undefined;
|
|
611
612
|
} & MouseEventHandles;
|
|
612
613
|
|
|
613
614
|
export declare const engines: {
|
package/package.json
CHANGED
package/src/Map/ref.ts
CHANGED
package/src/Map/types/index.ts
CHANGED
|
@@ -448,7 +448,7 @@ export const useHooks = ({
|
|
|
448
448
|
}) => {
|
|
449
449
|
const { viewer } = useCesium();
|
|
450
450
|
const tilesetRef = useRef<Cesium3DTilesetType>();
|
|
451
|
-
const { onLayerLoad } = useContext();
|
|
451
|
+
const { onLayerLoad, updateCredits } = useContext();
|
|
452
452
|
const layerIdRef = useRef(layer?.id);
|
|
453
453
|
layerIdRef.current = layer?.id;
|
|
454
454
|
|
|
@@ -801,6 +801,13 @@ export const useHooks = ({
|
|
|
801
801
|
[onLayerFetch, onLayerLoad],
|
|
802
802
|
);
|
|
803
803
|
|
|
804
|
+
useEffect(() => {
|
|
805
|
+
updateCredits?.();
|
|
806
|
+
return () => {
|
|
807
|
+
updateCredits?.();
|
|
808
|
+
};
|
|
809
|
+
}, [type, updateCredits]);
|
|
810
|
+
|
|
804
811
|
return {
|
|
805
812
|
tilesetUrl,
|
|
806
813
|
ref,
|
|
@@ -26,6 +26,7 @@ export type Context = {
|
|
|
26
26
|
position: [x: number, y: number, z: number],
|
|
27
27
|
) => [x: number, y: number] | undefined;
|
|
28
28
|
isPositionVisible?: (position: [x: number, y: number, z: number]) => boolean;
|
|
29
|
+
updateCredits?: () => void;
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
export const context = createContext<Context>({});
|
|
@@ -35,6 +35,8 @@ import {
|
|
|
35
35
|
Plane,
|
|
36
36
|
CameraEventType,
|
|
37
37
|
KeyboardEventModifier,
|
|
38
|
+
CreditDisplay,
|
|
39
|
+
Credit as CesiumCredit,
|
|
38
40
|
} from "cesium";
|
|
39
41
|
import { MutableRefObject, useMemo } from "react";
|
|
40
42
|
|
|
@@ -898,3 +900,35 @@ export function getExtrudedHeight(
|
|
|
898
900
|
}
|
|
899
901
|
return;
|
|
900
902
|
}
|
|
903
|
+
|
|
904
|
+
export function getCredits(viewer: Viewer) {
|
|
905
|
+
if (!viewer) return;
|
|
906
|
+
const creditDisplay = viewer.creditDisplay as
|
|
907
|
+
| (CreditDisplay & {
|
|
908
|
+
_currentFrameCredits: {
|
|
909
|
+
lightboxCredits: { _array: { credit?: CesiumCredit }[] };
|
|
910
|
+
screenCredits: { _array: { credit?: CesiumCredit }[] };
|
|
911
|
+
};
|
|
912
|
+
_currentCesiumCredit: CesiumCredit;
|
|
913
|
+
})
|
|
914
|
+
| undefined;
|
|
915
|
+
|
|
916
|
+
if (!creditDisplay) return;
|
|
917
|
+
|
|
918
|
+
const { lightboxCredits, screenCredits } = creditDisplay?._currentFrameCredits || {};
|
|
919
|
+
const cesiumCredits = creditDisplay._currentCesiumCredit;
|
|
920
|
+
|
|
921
|
+
const credits: {
|
|
922
|
+
html?: string;
|
|
923
|
+
}[] = [
|
|
924
|
+
...(cesiumCredits?.html ? [{ html: cesiumCredits.html }] : []),
|
|
925
|
+
...Array.from(lightboxCredits?._array ?? []).map(c => ({
|
|
926
|
+
html: c?.credit?.html,
|
|
927
|
+
})),
|
|
928
|
+
...Array.from(screenCredits?._array ?? []).map(c => ({
|
|
929
|
+
html: c?.credit?.html,
|
|
930
|
+
})),
|
|
931
|
+
];
|
|
932
|
+
|
|
933
|
+
return credits;
|
|
934
|
+
}
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
cartesianToLatLngHeight,
|
|
33
33
|
getExtrudedHeight,
|
|
34
34
|
getOverriddenScreenSpaceCameraOptions,
|
|
35
|
+
getCredits,
|
|
35
36
|
} from "../common";
|
|
36
37
|
import { attachTag, getTag } from "../Feature";
|
|
37
38
|
import { PickedFeature, pickManyFromViewportAsFeature } from "../pickMany";
|
|
@@ -974,6 +975,11 @@ export default function useEngineRef(
|
|
|
974
975
|
const p5 = [pp5.x, pp5.y, pp5.z] as Position3d;
|
|
975
976
|
return [p1, p2, p5];
|
|
976
977
|
},
|
|
978
|
+
getCredits: () => {
|
|
979
|
+
const viewer = cesium.current?.cesiumElement;
|
|
980
|
+
if (!viewer || viewer.isDestroyed()) return;
|
|
981
|
+
return getCredits(viewer);
|
|
982
|
+
},
|
|
977
983
|
};
|
|
978
984
|
}, [cesium]);
|
|
979
985
|
|
|
@@ -12,8 +12,6 @@ import {
|
|
|
12
12
|
GroundPrimitive,
|
|
13
13
|
ShadowMap,
|
|
14
14
|
ImageryLayer,
|
|
15
|
-
CreditDisplay,
|
|
16
|
-
Credit as CesiumCredit,
|
|
17
15
|
} from "cesium";
|
|
18
16
|
import { MutableRefObject, RefObject, useCallback, useEffect, useMemo, useRef } from "react";
|
|
19
17
|
import type { CesiumComponentRef, CesiumMovementEvent, RootEventTarget } from "resium";
|
|
@@ -40,7 +38,7 @@ import {
|
|
|
40
38
|
import { TimelineManagerRef } from "../../Map/useTimelineManager";
|
|
41
39
|
import { FEATURE_FLAGS } from "../../Visualizer/featureFlags";
|
|
42
40
|
|
|
43
|
-
import { isSelectable } from "./common";
|
|
41
|
+
import { getCredits, isSelectable } from "./common";
|
|
44
42
|
import { getTag, type Context as FeatureContext } from "./Feature";
|
|
45
43
|
import { arrayToCartecian3 } from "./helpers/sphericalHaromic";
|
|
46
44
|
import useCamera from "./hooks/useCamera";
|
|
@@ -653,6 +651,22 @@ export default ({
|
|
|
653
651
|
viewer.scene.requestRender();
|
|
654
652
|
}, []);
|
|
655
653
|
|
|
654
|
+
const onCreditsUpdateRef = useRef(onCreditsUpdate);
|
|
655
|
+
onCreditsUpdateRef.current = onCreditsUpdate;
|
|
656
|
+
const updateCredits = useCallback(() => {
|
|
657
|
+
if (!onCreditsUpdateRef.current) return;
|
|
658
|
+
// currently we don't have a proper way to get the credits update event
|
|
659
|
+
// wait for 3 seconds to get latest credits
|
|
660
|
+
// some internal property is been used here.
|
|
661
|
+
setTimeout(() => {
|
|
662
|
+
if (!onCreditsUpdateRef.current) return;
|
|
663
|
+
const viewer = cesium.current?.cesiumElement;
|
|
664
|
+
if (!viewer || viewer.isDestroyed()) return;
|
|
665
|
+
const credits: Credit[] = getCredits(viewer) ?? [];
|
|
666
|
+
onCreditsUpdateRef.current(credits);
|
|
667
|
+
}, 3000);
|
|
668
|
+
}, []);
|
|
669
|
+
|
|
656
670
|
const context = useMemo<FeatureContext>(
|
|
657
671
|
() => ({
|
|
658
672
|
selectionReason,
|
|
@@ -667,8 +681,17 @@ export default ({
|
|
|
667
681
|
toXYZ: engineAPI.toXYZ,
|
|
668
682
|
toWindowPosition: engineAPI.toWindowPosition,
|
|
669
683
|
isPositionVisible: engineAPI.isPositionVisible,
|
|
684
|
+
updateCredits,
|
|
670
685
|
}),
|
|
671
|
-
[
|
|
686
|
+
[
|
|
687
|
+
selectionReason,
|
|
688
|
+
engineAPI,
|
|
689
|
+
onLayerEdit,
|
|
690
|
+
onLayerVisibility,
|
|
691
|
+
onLayerLoad,
|
|
692
|
+
timelineManagerRef,
|
|
693
|
+
updateCredits,
|
|
694
|
+
],
|
|
672
695
|
);
|
|
673
696
|
|
|
674
697
|
useEffect(() => {
|
|
@@ -733,41 +756,6 @@ export default ({
|
|
|
733
756
|
unmountCamera?.();
|
|
734
757
|
}, [unmountCamera]);
|
|
735
758
|
|
|
736
|
-
const updateCredits = useCallback(() => {
|
|
737
|
-
if (!onCreditsUpdate) return;
|
|
738
|
-
// currently we don't have a proper way to get the credits update event
|
|
739
|
-
// wait for 3 seconds to get latest credits
|
|
740
|
-
// some internal property is been used here.
|
|
741
|
-
setTimeout(() => {
|
|
742
|
-
const creditDisplay = cesium.current?.cesiumElement?.creditDisplay as
|
|
743
|
-
| (CreditDisplay & {
|
|
744
|
-
_currentFrameCredits: {
|
|
745
|
-
lightboxCredits: { _array: { credit?: CesiumCredit }[] };
|
|
746
|
-
screenCredits: { _array: { credit?: CesiumCredit }[] };
|
|
747
|
-
};
|
|
748
|
-
_currentCesiumCredit: CesiumCredit;
|
|
749
|
-
})
|
|
750
|
-
| undefined;
|
|
751
|
-
|
|
752
|
-
if (!creditDisplay) return;
|
|
753
|
-
|
|
754
|
-
const { lightboxCredits, screenCredits } = creditDisplay?._currentFrameCredits || {};
|
|
755
|
-
const cesiumCredits = creditDisplay._currentCesiumCredit;
|
|
756
|
-
|
|
757
|
-
const credits: Credit[] = [
|
|
758
|
-
...(cesiumCredits?.html ? [{ html: cesiumCredits.html }] : []),
|
|
759
|
-
...Array.from(lightboxCredits?._array ?? []).map(c => ({
|
|
760
|
-
html: c?.credit?.html,
|
|
761
|
-
})),
|
|
762
|
-
...Array.from(screenCredits?._array ?? []).map(c => ({
|
|
763
|
-
html: c?.credit?.html,
|
|
764
|
-
})),
|
|
765
|
-
];
|
|
766
|
-
|
|
767
|
-
onCreditsUpdate(credits);
|
|
768
|
-
}, 3000);
|
|
769
|
-
}, [onCreditsUpdate]);
|
|
770
|
-
|
|
771
759
|
const handleTilesChange = useCallback(() => {
|
|
772
760
|
updateCredits();
|
|
773
761
|
}, [updateCredits]);
|