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 40d8092 commit 8366e70
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions typescript/packages/subsurface-viewer/src/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import type {
Viewport,
PickingInfo,
} from "@deck.gl/core/typed";
import { OrthographicView, OrbitView, PointLight } from "@deck.gl/core/typed";
import {
OrthographicView,
OrbitView,
PointLight,
LinearInterpolator,
FlyToInterpolator,
} from "@deck.gl/core/typed";
import type { Feature, FeatureCollection } from "geojson";
import React, { useEffect, useState, useCallback, useRef } from "react";
import JSON_CONVERTER_CONFIG from "../utils/configuration";
Expand Down Expand Up @@ -286,6 +292,7 @@ export interface ViewStateType {
rotationOrbit: number;
minZoom?: number;
maxZoom?: number;
transitionDuration?: number;
}

interface marginsType {
Expand Down Expand Up @@ -917,11 +924,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 8366e70

Please sign in to comment.