Skip to content

Commit d4790d8

Browse files
VincentNevermoreshengwei zhanghkfb
authored
add a callback function to display the selected wells (#1333)
* temp * temp * add a callback function to display the selected wells * add a callback function to display the selected wells * fix comments * fix issue when getSelectedWellsData is not provided * rename lasso layer to box selection layer * change box selection default visible to true * revert map layer changes * make variable lower case as suggested * fix comments * fix lint issue * fix comments * remove eslint comment * remove deprecrated prop - legend Co-authored-by: shengwei zhang <[email protected]> Co-authored-by: Håvard Bjerke <[email protected]>
1 parent 8b08056 commit d4790d8

File tree

5 files changed

+78
-42
lines changed

5 files changed

+78
-42
lines changed

react/src/lib/components/DeckGLMap/layers/LassoLayer/lassoLayer.stories.tsx renamed to react/src/lib/components/DeckGLMap/layers/BoxSelectionLayer/boxSelectionLayer.stories.tsx

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { FormControlLabel, makeStyles, Switch } from "@material-ui/core";
22
import { ComponentMeta, ComponentStory } from "@storybook/react";
3+
import { PickInfo } from "lib";
34
import React from "react";
45
import DeckGLMap from "../../DeckGLMap";
56

67
export default {
78
component: DeckGLMap,
8-
title: "DeckGLMap / Lasso Layer",
9+
title: "DeckGLMap / Box Selection Layer",
910
} as ComponentMeta<typeof DeckGLMap>;
1011

1112
const useStyles = makeStyles({
@@ -22,43 +23,30 @@ const useStyles = makeStyles({
2223
},
2324
});
2425

25-
export const lassoSelection: ComponentStory<typeof DeckGLMap> = (args) => {
26-
const [editedData, setEditedData] = React.useState(args.editedData);
26+
export const boxSelection: ComponentStory<typeof DeckGLMap> = () => {
2727
const [argsState, setArgsState] =
2828
React.useState<Record<string, unknown>>(enableLassoArgs);
2929
const [state, setState] = React.useState<boolean>(true);
3030

3131
const handleChange = React.useCallback(() => {
32-
const lassoLayer = enableLassoArgs.layers.filter(
33-
(item) => item["@@type"] === "LassoLayer"
32+
const boxSelectionLayer = enableLassoArgs.layers.filter(
33+
(item) => item["@@type"] === "BoxSelectionLayer"
3434
);
35-
if (lassoLayer[0].visible !== undefined) {
36-
lassoLayer[0].visible = !lassoLayer[0].visible;
35+
if (boxSelectionLayer[0].visible !== undefined) {
36+
boxSelectionLayer[0].visible = !boxSelectionLayer[0].visible;
3737
}
38-
if (lassoLayer[0].visible) {
38+
if (boxSelectionLayer[0].visible) {
3939
setArgsState(enableLassoArgs);
4040
} else {
4141
setArgsState(disableLassoArgs);
4242
}
4343
setState(!state);
4444
}, [state]);
4545

46-
React.useEffect(() => {
47-
setEditedData(args.editedData);
48-
}, [args.editedData]);
49-
5046
return (
5147
<>
5248
<div className={useStyles().main}>
53-
<DeckGLMap
54-
id={"DeckGL-Map"}
55-
{...argsState}
56-
editedData={editedData}
57-
setProps={(updatedProps) => {
58-
setEditedData(updatedProps);
59-
}}
60-
legend={{ visible: false }}
61-
/>
49+
<DeckGLMap id={"DeckGL-Map"} {...argsState} />
6250
</div>
6351
<div style={{ textAlign: "center" }}>
6452
<FormControlLabel
@@ -90,9 +78,8 @@ const disableLassoArgs = {
9078
data: "@@#resources.wellsData",
9179
},
9280
{
93-
"@@type": "LassoLayer",
81+
"@@type": "BoxSelectionLayer",
9482
visible: false,
95-
data: "@@#resources.wellsData",
9683
},
9784
],
9885
editedData: {},
@@ -117,9 +104,54 @@ const enableLassoArgs = {
117104
data: "@@#resources.wellsData",
118105
},
119106
{
120-
"@@type": "LassoLayer",
107+
"@@type": "BoxSelectionLayer",
121108
visible: true,
122-
data: "@@#resources.wellsData",
123109
},
124110
],
125111
};
112+
113+
export const boxSelectionWithCallback: ComponentStory<
114+
typeof DeckGLMap
115+
> = () => {
116+
const [data, setData] = React.useState<string[]>([]);
117+
const getSelectedWellsDataCallBack = React.useCallback(
118+
(pickingInfos: PickInfo[]) => {
119+
const selectedWells = pickingInfos
120+
.map((item) => item.object)
121+
.filter((item) => item.type === "Feature")
122+
.map((item) => item.properties["name"]) as string[];
123+
setData(selectedWells);
124+
},
125+
[]
126+
);
127+
const lassoArgsWithSelectedWellsDataCallback: Record<string, unknown> = {
128+
...disableLassoArgs,
129+
layers: [
130+
{
131+
"@@type": "WellsLayer",
132+
data: "@@#resources.wellsData",
133+
},
134+
{
135+
"@@type": "BoxSelectionLayer",
136+
visible: true,
137+
handleSelection: getSelectedWellsDataCallBack,
138+
},
139+
],
140+
};
141+
return (
142+
<>
143+
<div className={useStyles().main}>
144+
<DeckGLMap
145+
id={"DeckGL-Map"}
146+
{...lassoArgsWithSelectedWellsDataCallback}
147+
/>
148+
</div>
149+
<div>
150+
<div>Selected Wells:</div>
151+
{data.map((item) => (
152+
<div key={item}>{item}</div>
153+
))}
154+
</div>
155+
</>
156+
);
157+
};

react/src/lib/components/DeckGLMap/layers/LassoLayer/lassoLayer.tsx renamed to react/src/lib/components/DeckGLMap/layers/BoxSelectionLayer/boxSelectionLayer.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { ExtendedLayerProps } from "../utils/layerTools";
77
import { getSize } from "../wells/wellsLayer";
88
import { Color } from "@deck.gl/core/typed";
99
import { Feature } from "geojson";
10-
export interface LassoLayerProps<D> extends ExtendedLayerProps<D> {
10+
import { PickInfo } from "lib";
11+
export interface BoxSelectionLayerProps<D> extends ExtendedLayerProps<D> {
1112
mode: string; // One of modes in MODE_MAP
1213
selectedFeatureIndexes: number[];
1314
pickingInfos: PickingInfo[];
@@ -16,6 +17,7 @@ export interface LassoLayerProps<D> extends ExtendedLayerProps<D> {
1617
lineWidthScale: number;
1718
lineStyle: LineStyleAccessor;
1819
wellHeadStyle: WellHeadStyleAccessor;
20+
handleSelection: (pickingInfos: PickInfo[]) => void;
1921
}
2022

2123
type StyleAccessorFunction = (
@@ -42,8 +44,8 @@ type WellHeadStyleAccessor = {
4244

4345
// Composite layer that contains an Selection Lyaer from nebula.gl
4446
// See https://nebula.gl/docs/api-reference/layers/selection-layer
45-
export default class LassoLayer extends CompositeLayer<
46-
LassoLayerProps<FeatureCollection>
47+
export default class BoxSelectionLayer extends CompositeLayer<
48+
BoxSelectionLayerProps<FeatureCollection>
4749
> {
4850
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4951
setMultiSelection(pickingInfos: any[]): void {
@@ -68,7 +70,6 @@ export default class LassoLayer extends CompositeLayer<
6870
const isOrthographic =
6971
this.context.viewport.constructor.name === "OrthographicViewport";
7072
const positionFormat = isOrthographic ? "XY" : "XYZ";
71-
7273
const geoJsonLayer = new GeoJsonLayer({
7374
id: "geoJson",
7475
data: this.state["data"],
@@ -96,6 +97,9 @@ export default class LassoLayer extends CompositeLayer<
9697
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9798
onSelect: ({ pickingInfos }: any) => {
9899
this.setMultiSelection(pickingInfos);
100+
if (this.props.handleSelection) {
101+
this.props.handleSelection(pickingInfos);
102+
}
99103
},
100104
layerIds: ["wells-layer"],
101105
getTentativeFillColor: () => [255, 0, 255, 100],
@@ -109,7 +113,7 @@ export default class LassoLayer extends CompositeLayer<
109113
}
110114
}
111115

112-
LassoLayer.layerName = "LassoLayer";
113-
LassoLayer.defaultProps = layersDefaultProps[
114-
"LassoLayer"
115-
] as LassoLayerProps<FeatureCollection>;
116+
BoxSelectionLayer.layerName = "BoxSelectionLayer";
117+
BoxSelectionLayer.defaultProps = layersDefaultProps[
118+
"BoxSelectionLayer"
119+
] as BoxSelectionLayerProps<FeatureCollection>;

react/src/lib/components/DeckGLMap/layers/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export { default as SelectableGeoJsonLayer } from "./selectable_geojson/selectab
1313
export { default as NorthArrow3DLayer } from "./northarrow/northArrow3DLayer";
1414
export { default as UnfoldedGeoJsonLayer } from "./intersection/unfoldedGeoJsonLayer";
1515
export { default as Grid3DLayer } from "./grid3d/grid3dLayer";
16-
export { default as LassoLayer } from "./LassoLayer/lassoLayer";
16+
export { default as BoxSelectionLayer } from "./BoxSelectionLayer/boxSelectionLayer";
1717

1818
export { AxesLayerProps } from "./axes/axesLayer";
1919
export { Axes2DLayerProps } from "./axes2d/axes2DLayer";
@@ -28,4 +28,4 @@ export { PieChartLayerProps } from "./piechart/pieChartLayer";
2828
export { Map3DLayerProps } from "./terrain/map3DLayer";
2929
export { WellsLayerProps } from "./wells/wellsLayer";
3030
export { Grid3DLayerProps } from "./grid3d/grid3dLayer";
31-
export { LassoLayerProps } from "./LassoLayer/lassoLayer";
31+
export { BoxSelectionLayerProps } from "./BoxSelectionLayer/boxSelectionLayer";

react/src/lib/components/DeckGLMap/layers/layersDefaultProps.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,14 @@ export const layersDefaultProps: Record<string, unknown> = {
158158
features: [],
159159
},
160160
},
161-
LassoLayer: {
162-
"@@type": "LassoLayer",
163-
name: "Lasso",
164-
id: "lasso-layer",
161+
BoxSelectionLayer: {
162+
"@@type": "BoxSelectionLayer",
163+
name: "boxSelection",
164+
id: "boxSelection-layer",
165165
pickable: true,
166-
visible: false,
166+
visible: true,
167167

168-
// Props used to get/set data in the drawing layer.
168+
// Props used to get/set data in the box selection layer.
169169
selectedFeatureIndexes: [] as number[],
170170
data: {
171171
type: "FeatureCollection",

react/src/lib/components/DeckGLMap/layers/map/mapLayer.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ export const ColorMapRange: ComponentStory<typeof DeckGLMap> = (args) => {
907907
max={41048}
908908
defaultValue={41048}
909909
step={1000}
910-
onChangeCommitted={handleChange}
910+
onChange={handleChange}
911911
/>
912912
</>
913913
);

0 commit comments

Comments
 (0)