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: Enable left click to specify camera anchor/rotation point #1775 #1776

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Changes from all 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
21 changes: 20 additions & 1 deletion typescript/packages/subsurface-viewer/src/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export interface ViewStateType {
rotationOrbit: number;
minZoom?: number;
maxZoom?: number;
transitionDuration?: number;
}

interface marginsType {
Expand Down Expand Up @@ -917,11 +918,29 @@ const Map: React.FC<MapProps> = ({
infos: PickingInfo[],
event: MjolnirEvent
): void => {
if ((event as MjolnirPointerEvent).leftButton) {
// Left button click identifies new camera rotation anchor.
const viewstateKeys = Object.keys(viewStates);
if (infos.length >= 1 && viewstateKeys.length === 1) {
const info = infos[0];
if (info.coordinate) {
const x = info.coordinate[0];
const y = info.coordinate[1];
const z = info.coordinate[2];

const vs = cloneDeep(viewStates);
vs[viewstateKeys[0]].target = [x, y, z];
vs[viewstateKeys[0]].transitionDuration = 1000;
setViewStates(vs);
}
}
}

if (!onMouseEvent) return;
const ev = handleMouseEvent(type, infos, event);
onMouseEvent(ev);
},
[onMouseEvent]
[onMouseEvent, viewStates]
);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down