Skip to content

Commit

Permalink
add min pitch to CESIUM_CONFIG
Browse files Browse the repository at this point in the history
  • Loading branch information
mxfh committed Oct 1, 2024
1 parent 3316e8c commit 68188ee
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ export const GeoportalMap = () => {
pointerEvents: isMode2d ? "none" : "auto",
}}
>
<CustomViewer containerRef={container3dMapRef}></CustomViewer>
<CustomViewer containerRef={container3dMapRef} minPitch={CESIUM_CONFIG.camera.minPitch} ></CustomViewer>
</div>
)}
</>
Expand Down
3 changes: 3 additions & 0 deletions apps/geoportal/src/app/config/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export const CESIUM_CONFIG: CesiumConfig = {
duration: 100,
},
},
camera: {
minPitch: 30
},
baseUrl: `${APP_BASE_PATH}${CESIUM_PATHNAME}`,
pathName: CESIUM_PATHNAME,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type CustomViewerProps = {

//disableZoomRestrictions?: boolean; // todo
//minZoom?: number; // todo
minPitch?: number;
globe?: {
// https://cesium.com/learn/cesiumjs/ref-doc/Globe.html
baseColor?: Color;
Expand Down Expand Up @@ -99,6 +100,7 @@ function CustomViewer(props: CustomViewerProps) {
},
containerRef,
enableLocationHashUpdate = true,
minPitch,
} = props;

const previousViewerRef = useRef<Viewer | null>(null); // track viewer changes
Expand Down Expand Up @@ -130,7 +132,7 @@ function CustomViewer(props: CustomViewerProps) {
useTransitionTimeout();
useDisableSSCC();
useCameraRollSoftLimiter();
useCameraPitchHardLimiter();
useCameraPitchHardLimiter(minPitch);

useEffect(() => {
if (viewer && enableLocationHashUpdate && !isMode2d) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import {
useViewerIsMode2d,
} from "../../CustomViewerContextProvider";

const useCameraPitchHardLimiter = (minPitch = CeMath.toRadians(-(30))) => {
const DEFAULT_MIN_PITCH = 12;

const useCameraPitchHardLimiter = (minPitchDeg = DEFAULT_MIN_PITCH) => {
const { viewer } = useCesiumCustomViewer();
const dispatch = useDispatch();
const isMode2d = useViewerIsMode2d();
const collisions = useScreenSpaceCameraControllerEnableCollisionDetection();
const lastPitch = useRef<number | null>(null);
const lastPosition = useRef<Cartographic | null>(null);
const minPitchRad = CeMath.toRadians(-minPitchDeg);
const clearLast = () => {
lastPitch.current = null;
lastPosition.current = null;
Expand All @@ -27,12 +30,12 @@ const useCameraPitchHardLimiter = (minPitch = CeMath.toRadians(-(30))) => {
);
clearLast();
const onUpdate = async () => {
const isPitchTooLow = camera.pitch > minPitch;
const isPitchTooLow = camera.pitch > minPitchRad;
if (isPitchTooLow) {
console.log(
"LISTENER HOOK [2D3D|CESIUM|CAMERA]: reset pitch",
camera.pitch,
minPitch,
minPitchRad,
);
if (lastPitch.current !== null && lastPosition.current !== null) {
const { latitude, longitude } = camera.positionCartographic;
Expand All @@ -43,7 +46,7 @@ const useCameraPitchHardLimiter = (minPitch = CeMath.toRadians(-(30))) => {
),
orientation: {
heading: camera.heading,
pitch: minPitch,
pitch: minPitchRad,
roll: camera.roll,
},
});
Expand All @@ -57,7 +60,7 @@ const useCameraPitchHardLimiter = (minPitch = CeMath.toRadians(-(30))) => {
scene.preUpdate.removeEventListener(onUpdate);
};
}
}, [viewer, minPitch, collisions, isMode2d, dispatch]);
}, [viewer, minPitchRad, collisions, isMode2d, dispatch]);
};

export default useCameraPitchHardLimiter;
3 changes: 3 additions & 0 deletions types/cesium-config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export type CesiumConfig = {
duration: number;
};
};
camera: {
minPitch: number;
};
baseUrl: string;
pathName: string;
};

0 comments on commit 68188ee

Please sign in to comment.