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

Opacity #1272

Merged
merged 6 commits into from
Nov 7, 2022
Merged

Opacity #1272

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions react/src/lib/components/DeckGLMap/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
} from "../../../inputSchema/schemaValidationUtil";
import { LayerPickInfo } from "../layers/utils/layerTools";
import { getLayersByType } from "../layers/utils/layerTools";
import { getWellLayerByTypeAndSelectedWells } from "../layers/utils/layerTools";
import { WellsLayer } from "../layers";

import { isEmpty, isEqual } from "lodash";
Expand Down Expand Up @@ -616,9 +617,33 @@ const Map: React.FC<MapProps> = ({
}
}, [selection]);

useEffect(() => {
const layers = deckRef.current?.deck?.props.layers;
if (layers) {
const wellslayer = getLayersByType(
layers,
"WellsLayer"
)?.[0] as WellsLayer;

wellslayer?.setSelection(selection?.well, selection?.selection);
}
}, [selection]);

// multiple well layers
const [multipleWells, setMultipleWells] = useState<string[]>([]);
const [selectedWell, setSelectedWell] = useState<string>("");

useEffect(() => {
const layers = deckRef.current?.deck?.props.layers;
if (layers) {
const wellslayer = getWellLayerByTypeAndSelectedWells(
layers,
"WellsLayer",
selectedWell
)?.[0] as WellsLayer;
wellslayer?.setMultiSelection(multipleWells);
}
}, [multipleWells]);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [hoverInfo, setHoverInfo] = useState<any>([]);
const onHover = useCallback(
Expand Down Expand Up @@ -867,6 +892,7 @@ const Map: React.FC<MapProps> = ({
// @ts-expect-error this prop doesn't exists directly on DeckGL, but on Deck.Context
userData={{
setEditedData: (updated_prop: Record<string, unknown>) => {
setSelectedWell(updated_prop["selectedWell"] as string);
if (
Object.keys(updated_prop).includes("selectedWell")
) {
Expand Down
37 changes: 37 additions & 0 deletions react/src/lib/components/DeckGLMap/layers/utils/layerTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,43 @@ export function getLayersByType(layers: LayersList, type: string): LayersList {
return layers.filter((l) => l?.constructor.name === type);
}

export type NewLayersList = LayersList & {
id: string;
props: prop;
};

type prop = {
data: wellData;
};

type wellData = {
features: feature[];
type: string;
unit?: string;
};

type feature = {
properties: {
name: string;
};
};

export function getWellLayerByTypeAndSelectedWells(
layers: LayersList,
type: string,
selectedWell: string
): LayersList {
if (!layers) return [];
return layers.filter((l) => {
return (
l?.constructor.name === type &&
(l as NewLayersList).props.data.features.find(
(item) => item.properties.name === selectedWell
)
);
});
}

export function getLayersById(layers: LayersList, id: string): LayersList {
if (!layers) return [];
return layers.filter((l) => (l as Layer).id === id);
Expand Down
62 changes: 61 additions & 1 deletion react/src/lib/components/DeckGLMap/layers/wells/wellsLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ export default class WellsLayer extends CompositeLayer<
}
}

setMultiSelection(wells: string[] | undefined): void {
if (this.internalState) {
this.setState({
selectedMultiWells: wells,
});
}
}

shouldUpdateState({ changeFlags }: UpdateParameters<this>): boolean {
return (
changeFlags.viewportChanged ||
Expand Down Expand Up @@ -382,6 +390,32 @@ export default class WellsLayer extends CompositeLayer<
})
);

// Highlight the multi selected wells.
const highlightMultiWells = new UnfoldedGeoJsonLayer(
this.getSubLayerProps({
id: "highlight2",
data: getWellObjectsByName(
data.features,
this.state["selectedMultiWells"]
),
pickable: false,
stroked: false,
positionFormat,
pointRadiusUnits: "pixels",
lineWidthUnits: "pixels",
pointRadiusScale: this.props.pointRadiusScale,
lineWidthScale: this.props.lineWidthScale,
getLineWidth: getSize(LINE, this.props.lineStyle?.width, -1),
getPointRadius: getSize(
POINT,
this.props.wellHeadStyle?.size,
2
),
getFillColor: [255, 140, 0],
getLineColor: [255, 140, 0],
})
);

const log_layer = new PathLayer<LogCurveDataType>(
this.getSubLayerProps({
id: "log_curve",
Expand Down Expand Up @@ -508,7 +542,15 @@ export default class WellsLayer extends CompositeLayer<
})
);

return [outline, log_layer, colors, highlight, selection_layer, names];
return [
outline,
log_layer,
colors,
highlight,
highlightMultiWells,
selection_layer,
names,
];
}

getPickingInfo({ info }: { info: PickingInfo }): WellsPickInfo {
Expand Down Expand Up @@ -671,6 +713,24 @@ function getWellObjectByName(
);
}

function getWellObjectsByName(
wells_data: Feature[],
name: string[]
): Feature[] | undefined {
const res: Feature[] = [];
for (let i = 0; i < name?.length; i++) {
wells_data?.find((item) => {
if (
item.properties?.["name"]?.toLowerCase() ===
name[i]?.toLowerCase()
) {
res.push(item);
}
});
}
return res;
}

function getPointGeometry(well_object: Feature): Point {
return (well_object.geometry as GeometryCollection)?.geometries.find(
(item: { type: string }) => item.type == "Point"
Expand Down