Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react-components): Preserve camera pivot point on Reset to Home #4686

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion react-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cognite/reveal-react-components",
"version": "0.55.0",
"version": "0.55.1",
"exports": {
".": {
"import": "./dist/index.js",
Expand Down
16 changes: 16 additions & 0 deletions react-components/src/hooks/useSceneDefaultCamera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,23 @@ export const useSceneDefaultCamera = (

return {
fitCameraToSceneDefault: () => {
const initialCameraState = viewer.cameraManager.getCameraState();

viewer.cameraManager.setCameraState({ position, target });

// Check if camera pivot point is in origin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add TODO comment here

// If not, preserve the target
if (
!(
initialCameraState.target.x === 0 &&
initialCameraState.target.y === 0 &&
initialCameraState.target.z === 0
)
) {
viewer.cameraManager.setCameraState({
target: initialCameraState.target
});
}
},
isFetched: true
};
Expand Down
6 changes: 0 additions & 6 deletions react-components/stories/SceneContainer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
useSceneDefaultCamera,
withSuppressRevealEvents
} from '../src';
import { type DefaultCameraManager } from '@cognite/reveal';
import { ToolBar } from '@cognite/cogs.js';
import styled from 'styled-components';

Expand Down Expand Up @@ -79,11 +78,6 @@ const SceneContainerStoryContent = ({
const { fitCameraToSceneDefault } = useSceneDefaultCamera(sceneExternalId, sceneSpaceId);

useEffect(() => {
(reveal.cameraManager as DefaultCameraManager).setCameraControlsOptions({
changeCameraTargetOnClick: true,
mouseWheelAction: 'zoomToCursor'
});

fitCameraToSceneDefault();
}, [reveal, fitCameraToSceneDefault]);
return (
Expand Down
Loading