Skip to content

Commit

Permalink
addresses #119 #144
Browse files Browse the repository at this point in the history
  • Loading branch information
mxfh committed Sep 24, 2024
1 parent 14ca490 commit 2df98ba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const OFFSCREEN_RESOLUTION_SCALE = 1 / 64;
export const TRANSITION_DELAY = 1000;

function CustomViewer(props: CustomViewerProps) {
const { setViewer, imageryLayer } = useCesiumCustomViewer();
const { viewer, setViewer, imageryLayer } = useCesiumCustomViewer();
const dispatch = useDispatch();
const home = useViewerHome();
const homeOffset = useViewerHomeOffset();
Expand Down Expand Up @@ -125,8 +125,6 @@ function CustomViewer(props: CustomViewerProps) {
const setCollisions = (v: boolean) => dispatch(setScreenSpaceCameraControllerEnableCollisionDetection(v));



const [viewer, setComponentStateViewer] = useState<Viewer | null>(null);
const previousViewerRef = useRef<Viewer | null>(null); // track viewer changes
const previousIsMode2d = useRef<boolean | null>(null);
const previousIsSecondaryStyle = useRef<boolean | null>(null);
Expand Down Expand Up @@ -330,11 +328,11 @@ function CustomViewer(props: CustomViewerProps) {
useTransitionTimeout();
useDisableSSCC();

/*
useEffect(() => {
if (!viewer) return;
console.log("[CESIUM] HOOK Track user focus")
/*
const canvas = viewer.canvas;
// Ensure the canvas can receive focus
Expand All @@ -361,23 +359,13 @@ function CustomViewer(props: CustomViewerProps) {
canvas.removeEventListener("mousedown", handleMouseDown);
canvas.removeEventListener("mousemove", handleMouseDown);
};
*/
}, [viewer]);
*/


//const viewerRef = useCesiumCustomViewer();

/*
const viewerCallback = useCallback((node) => {
if (node !== null) {
setComponentStateViewer(node.cesiumElement);
//setViewer && setViewer(node.cesiumElement);
}
}, [viewerRef]);
*/
const viewerRef = useCallback((node) => {
if (node !== null) {
setComponentStateViewer(node.cesiumElement);
//setComponentStateViewer(node.cesiumElement);
setViewer && setViewer(node.cesiumElement);
}
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,15 @@ export const useLogCesiumRenderIn2D = () => {
const isAnimating = useViewerIsAnimating();
const transition = useViewerCurrentTransition();

const isMode2dRef = useRef(isMode2d);
const transitionRef = useRef(transition);
const isAnimatingRef = useRef(isAnimating);

useEffect(() => {
if (!viewer) return;

const logRender = () => {
if (isMode2dRef.current) {
if (isMode2d) {
console.info(
"[CESIUM|2D3D] Cesium got rendered while in 2D mode",
isAnimatingRef.current,
transitionRef.current,
isAnimating,
transition,
isMode2d,
isMode2dRef.current,
);
}
};
Expand All @@ -62,7 +56,7 @@ export const useLogCesiumRenderIn2D = () => {
return () => {
viewer.scene.postRender.removeEventListener(logRender);
};
}, [viewer]);
}, [viewer, isMode2d, isAnimating, transition]);
};

export const useInitializeViewer = (
Expand Down
10 changes: 7 additions & 3 deletions libraries/mapping/engines/cesium/src/lib/utils/cesiumHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ export const cameraToCartographicDegrees = (camera: Camera) => {
latitude: CeMath.toDegrees(latitude),
longitude: CeMath.toDegrees(longitude),
height,
heightApprox: height - EARTH_RADIUS,
};
};

Expand Down Expand Up @@ -737,7 +736,7 @@ export const cesiumCenterPixelSizeToLeafletZoom = (
export const leafletToCesium = (
viewer: Viewer,
leaflet: LeafletMap,
{ cause, onComplete }: { cause?: string, onComplete?: Function } = {},
{ cause, onComplete }: { cause?: string; onComplete?: Function } = {},
) => {
const { lat, lng } = leaflet.getCenter();
const zoom = leaflet.getZoom();
Expand All @@ -752,7 +751,12 @@ export const leafletToCesiumCamera = (
limit = 5,
cause = "not specified",
onComplete,
}: { epsilon?: number; limit?: number; cause?: string; onComplete?: Function } = {},
}: {
epsilon?: number;
limit?: number;
cause?: string;
onComplete?: Function;
} = {},
) => {
const lngRad = CeMath.toRadians(lng);
const latRad = CeMath.toRadians(lat);
Expand Down

0 comments on commit 2df98ba

Please sign in to comment.