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

add a callback function to display the selected wells #1333

Merged
merged 16 commits into from
Dec 7, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ const disableLassoArgs = {
{
"@@type": "LassoLayer",
visible: false,
data: "@@#resources.wellsData",
},
],
editedData: {},
Expand All @@ -119,7 +118,53 @@ const enableLassoArgs = {
{
"@@type": "LassoLayer",
visible: true,
data: "@@#resources.wellsData",
},
],
};

export const lassoSelectionWithCallback: ComponentStory<
typeof DeckGLMap
> = () => {
const [data, setData] = React.useState<string[]>([]);
const getSelectedWellsDataCallBack = React.useCallback(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(pickingInfos: any[]) => {
const selectedWells = pickingInfos
.map((item) => item.object)
.filter((item) => item.type === "Feature")
.map((item) => item.properties["name"]) as string[];
setData(selectedWells);
},
[]
);
const lassoArgsWithSelectedWellsDataCallback: Record<string, unknown> = {
...disableLassoArgs,
layers: [
{
"@@type": "WellsLayer",
data: "@@#resources.wellsData",
},
{
"@@type": "LassoLayer",
visible: true,
getSelectedWellsData: getSelectedWellsDataCallBack,
},
],
};
return (
<>
<div className={useStyles().main}>
<DeckGLMap
id={"DeckGL-Map"}
{...lassoArgsWithSelectedWellsDataCallback}
legend={{ visible: false }}
/>
</div>
<div>
{data.map((item) => (
<div key={item}>{item}</div>
))}
</div>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export interface LassoLayerProps<D> extends ExtendedLayerProps<D> {
lineWidthScale: number;
lineStyle: LineStyleAccessor;
wellHeadStyle: WellHeadStyleAccessor;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getSelectedWellsData: (pickingInfos: any[]) => void;
}

type StyleAccessorFunction = (
Expand Down Expand Up @@ -68,7 +70,6 @@ export default class LassoLayer extends CompositeLayer<
const isOrthographic =
this.context.viewport.constructor.name === "OrthographicViewport";
const positionFormat = isOrthographic ? "XY" : "XYZ";

const geoJsonLayer = new GeoJsonLayer({
id: "geoJson",
data: this.state["data"],
Expand Down Expand Up @@ -96,6 +97,9 @@ export default class LassoLayer extends CompositeLayer<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onSelect: ({ pickingInfos }: any) => {
this.setMultiSelection(pickingInfos);
if (this.props.getSelectedWellsData) {
this.props.getSelectedWellsData(pickingInfos);
}
},
layerIds: ["wells-layer"],
getTentativeFillColor: () => [255, 0, 255, 100],
Expand Down