-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-components): added reset camera position to scene data pos…
…ition (#4040) * Added button for reset camera position to default as config in scene * update camera reset button to use useCameraFromScene hook * enabled fallback for camera to fit to all models if scene externalId is not provided * exported useCameraFromScene hook * fixed merge error * update visual test iage * moved reset camera to Scene story, reverted visual image & updated the reset camera hook to be called outside conditional loop * updated variable name --------- Co-authored-by: cognite-bulldozer[bot] <51074376+cognite-bulldozer[bot]@users.noreply.github.com>
- Loading branch information
1 parent
5ff1f04
commit 0eeaa99
Showing
5 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
react-components/src/components/RevealToolbar/ResetCameraButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/*! | ||
* Copyright 2023 Cognite AS | ||
*/ | ||
|
||
import { type ReactElement, useCallback } from 'react'; | ||
import { Button, Tooltip as CogsTooltip } from '@cognite/cogs.js'; | ||
import { useTranslation } from '../i18n/I18n'; | ||
import { useCameraNavigation } from '../../hooks/useCameraNavigation'; | ||
import { useSceneDefaultCamera } from '../../hooks/useSceneDefaultCamera'; | ||
|
||
type ResetCameraButtonProps = { | ||
sceneExternalId?: string; | ||
sceneSpaceId?: string; | ||
}; | ||
|
||
export const ResetCameraButton = ({ | ||
sceneExternalId, | ||
sceneSpaceId | ||
}: ResetCameraButtonProps): ReactElement => { | ||
const { t } = useTranslation(); | ||
const cameraNavigation = useCameraNavigation(); | ||
const resetToDefaultSceneCamera = useSceneDefaultCamera( | ||
sceneExternalId ?? '', | ||
sceneSpaceId ?? '' | ||
); | ||
|
||
const resetCameraToHomePosition = useCallback(() => { | ||
if (sceneExternalId !== undefined && sceneSpaceId !== undefined) { | ||
resetToDefaultSceneCamera.fitCameraToSceneDefault(); | ||
return; | ||
} | ||
cameraNavigation.fitCameraToAllModels(); | ||
}, [sceneExternalId, sceneSpaceId, cameraNavigation, resetToDefaultSceneCamera]); | ||
|
||
return ( | ||
<CogsTooltip | ||
content={t('RESET_CAMERA_TO_HOME', 'Reset camera to home')} | ||
placement="right" | ||
appendTo={document.body}> | ||
<Button | ||
type="ghost" | ||
icon="Restore" | ||
aria-label="Reset camera to home" | ||
onClick={resetCameraToHomePosition} | ||
/> | ||
</CogsTooltip> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-18 Bytes
(100%)
...sts/__screenshots__/Toolbar.stories.spec.ts/cad-model-container-storybook-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.