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
1 change: 1 addition & 0 deletions react/src/lib/components/DeckGLMap/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@ const Map: React.FC<MapProps> = ({
},
[viewStates]
);

if (!deckGLViews || isEmpty(deckGLViews) || isEmpty(deckGLLayers))
return null;
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,51 @@ const enableLassoArgs = {
},
],
};

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",
hkfb marked this conversation as resolved.
Show resolved Hide resolved
data: "@@#resources.wellsData",
},
{
"@@type": "LassoLayer",
hkfb marked this conversation as resolved.
Show resolved Hide resolved
visible: true,
data: "@@#resources.wellsData",
hkfb marked this conversation as resolved.
Show resolved Hide resolved
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;
hkfb marked this conversation as resolved.
Show resolved Hide resolved
}

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,7 @@ export default class LassoLayer extends CompositeLayer<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onSelect: ({ pickingInfos }: any) => {
this.setMultiSelection(pickingInfos);
this.props.getSelectedWellsData(pickingInfos);
},
layerIds: ["wells-layer"],
getTentativeFillColor: () => [255, 0, 255, 100],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class CustomModifyMode extends ModifyMode {
super.handleKeyUp(event, props);

if (event.key === "Delete") {
console.log("In");
hkfb marked this conversation as resolved.
Show resolved Hide resolved
const updatedData = new ImmutableFeatureCollection(props.data)
.deleteFeatures(props.selectedIndexes)
.getObject();
Expand Down Expand Up @@ -154,6 +155,7 @@ export default class DrawingLayer extends CompositeLayer<
// Callback for various editing events. Most events will update this component
// through patches sent to the map parent. See patchLayerPropsin layerTools.ts.
_onEdit(editAction: EditAction<FeatureCollection>): void {
console.log(editAction.editType);
switch (editAction.editType) {
case "addFeature":
this.setState({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ export default class WellsLayer extends CompositeLayer<
if (!(this.props.data as unknown as FeatureCollection).features) {
return [];
}

const refine = this.props.refine;
const data = refine
? splineRefine(this.props.data as unknown as FeatureCollection) // smooth well paths.
Expand Down