Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Merge branch 'main' into feature/fix-image-position
Browse files Browse the repository at this point in the history
  • Loading branch information
keiya01 authored May 30, 2022
2 parents be11a2e + 4fd0eb3 commit 1df5e56
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/components/molecules/Visualizer/Engine/Cesium/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Cartesian3,
CesiumWidget,
PerspectiveFrustum,
OrthographicOffCenterFrustum,
Viewer,
HeightReference,
ShadowMode,
Expand Down Expand Up @@ -303,15 +304,18 @@ export const animateFOV = ({
export const getCamera = (viewer: Viewer | CesiumWidget | undefined): Camera | undefined => {
if (!viewer || viewer.isDestroyed() || !viewer.camera || !viewer.scene) return undefined;
const { camera } = viewer;
if (!(camera.frustum instanceof PerspectiveFrustum)) return;

const ellipsoid = viewer.scene.globe.ellipsoid;
const { latitude, longitude, height } = ellipsoid.cartesianToCartographic(camera.position);
if (
!(
camera.frustum instanceof PerspectiveFrustum ||
camera.frustum instanceof OrthographicOffCenterFrustum
)
)
return;
const { latitude, longitude, height } = camera.positionCartographic;
const lat = CesiumMath.toDegrees(latitude);
const lng = CesiumMath.toDegrees(longitude);
const { heading, pitch, roll } = camera;
const { fov } = camera.frustum;

const fov = camera.frustum instanceof PerspectiveFrustum ? camera.frustum.fov : 1;
return { lng, lat, height, heading, pitch, roll, fov };
};

Expand Down
4 changes: 4 additions & 0 deletions src/components/molecules/Visualizer/Engine/Cesium/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ export default ({
[property?.default?.bgcolor],
);

useEffect(() => {
engineAPI.changeSceneMode(property?.default?.sceneMode, 0);
}, [property?.default?.sceneMode, engineAPI]);

// move to initial position at startup
const initialCameraFlight = useRef(false);

Expand Down
16 changes: 16 additions & 0 deletions src/components/molecules/Visualizer/Engine/Cesium/useEngineRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ export default function useEngineRef(
if (!viewer || viewer.isDestroyed()) return;
viewer?.scene?.camera.zoomOut(amount);
},
changeSceneMode: (sceneMode, duration = 2) => {
const viewer = cesium.current?.cesiumElement;
if (!viewer || viewer.isDestroyed() || !viewer.scene) return;
switch (sceneMode) {
case "2d":
viewer?.scene?.morphTo2D(duration);
break;
case "columbus":
viewer?.scene?.morphToColumbusView(duration);
break;
case "3d":
default:
viewer?.scene?.morphTo3D(duration);
break;
}
},
builtinPrimitives,
clusterComponent: Cluster,
};
Expand Down
4 changes: 4 additions & 0 deletions src/components/molecules/Visualizer/Engine/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ export type EngineRef = {
lookAt: (destination: LookAtDestination, options?: CameraOptions) => void;
zoomIn: (amount: number) => void;
zoomOut: (amount: number) => void;
changeSceneMode: (sceneMode: SceneMode | undefined, duration?: number) => void;
isMarshalable?: boolean | "json" | ((target: any) => boolean | "json");
builtinPrimitives?: Record<string, Component>;
pluginApi?: any;
clusterComponent?: ComponentType<ClusterProps>;
};

export type SceneMode = "3d" | "2d" | "columbus";

export type FlyToDestination = {
/** Degrees */
lat?: number;
Expand Down Expand Up @@ -76,6 +79,7 @@ export type SceneProperty = {
skybox?: boolean;
bgcolor?: string;
ion?: string;
sceneMode?: SceneMode; // default: scene3d
};
cameraLimiter?: {
cameraLimitterEnabled?: boolean;
Expand Down

0 comments on commit 1df5e56

Please sign in to comment.