Skip to content

Commit

Permalink
feat: Expose onDrag and getCursor functions from DeckGL compone…
Browse files Browse the repository at this point in the history
…nt (#2415)
  • Loading branch information
rubenthoms authored Jan 20, 2025
1 parent aa0f293 commit fa51d16
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions typescript/packages/subsurface-viewer/src/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
View,
Viewport,
} from "@deck.gl/core";
import type { DeckGLRef } from "@deck.gl/react";
import type { DeckGLProps, DeckGLRef } from "@deck.gl/react";
import DeckGL from "@deck.gl/react";

import {
Expand Down Expand Up @@ -350,6 +350,16 @@ export interface MapProps {

onDragStart?: (info: PickingInfo, event: MjolnirGestureEvent) => void;
onDragEnd?: (info: PickingInfo, event: MjolnirGestureEvent) => void;
onDrag?: (info: PickingInfo, event: MjolnirGestureEvent) => void;

/**
* Override default cursor with a callback.
* @param cursorState
* @returns cursor string
* @default "grabbing" when dragging, "default" otherwise
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
*/
getCursor?: DeckGLProps["getCursor"];

triggerResetMultipleWells?: number;

Expand Down Expand Up @@ -421,6 +431,8 @@ const Map: React.FC<MapProps> = ({
onRenderingProgress,
onDragStart,
onDragEnd,
onDrag,
getCursor,
lights,
triggerResetMultipleWells,
verticalScale,
Expand Down Expand Up @@ -758,6 +770,20 @@ const Map: React.FC<MapProps> = ({
[getCameraPosition, viewController]
);

const getCursorFunc = useCallback(
function getCursorFunc(
cursorState: Parameters<
Exclude<DeckGLProps["getCursor"], undefined>
>[0]
): string {
if (getCursor) {
return getCursor(cursorState);
}
return cursorState.isDragging ? "grabbing" : "default";
},
[getCursor]
);

const effects = parseLights(lights) ?? [];

const [deckGlViews, deckGlViewState] = useMemo(() => {
Expand Down Expand Up @@ -831,9 +857,7 @@ const Map: React.FC<MapProps> = ({
},
colorTables: colorTables,
}}
getCursor={({ isDragging }): string =>
isDragging ? "grabbing" : "default"
}
getCursor={getCursorFunc}
getTooltip={getTooltip}
ref={deckRef}
onViewStateChange={onViewStateChange}
Expand All @@ -843,6 +867,7 @@ const Map: React.FC<MapProps> = ({
effects={effects}
onDragStart={onDragStart}
onDragEnd={onDragEnd}
onDrag={onDrag}
onResize={onResize}
pickingRadius={pickingRadius}
>
Expand Down

0 comments on commit fa51d16

Please sign in to comment.