Skip to content

Commit

Permalink
feat: Enable left click to specify camera anchor/rotation point #1775 (
Browse files Browse the repository at this point in the history
  • Loading branch information
nilscb committed Nov 15, 2023
1 parent 67e59bd commit 533f527
Showing 1 changed file with 20 additions and 1 deletion.
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

0 comments on commit 533f527

Please sign in to comment.