Skip to content

Commit

Permalink
Add generic polygon layer
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKallekleiv committed Aug 16, 2024
1 parent ea5d0c5 commit 2ca6abf
Show file tree
Hide file tree
Showing 8 changed files with 441 additions and 23 deletions.
129 changes: 129 additions & 0 deletions frontend/src/modules/2DViewer/layers/FaultPolygonLayer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { PolygonData_api } from "@api";
import { apiService } from "@framework/ApiService";
import { EnsembleIdent } from "@framework/EnsembleIdent";
import { defaultColorPalettes } from "@framework/utils/colorPalettes";
import { ColorSet } from "@lib/utils/ColorSet";
import { BaseLayer, BoundingBox, LayerTopic } from "@modules/_shared/layers/BaseLayer";
import { LayerManager } from "@modules/_shared/layers/LayerManager";
import { QueryClient } from "@tanstack/query-core";

import { isEqual } from "lodash";

const STALE_TIME = 60 * 1000;
const CACHE_TIME = 60 * 1000;

export type FaultPolygonLayerSettings = {
ensembleIdent: EnsembleIdent | null;
realizationNum: number | null;
polygonName: string | null;
attribute: string | null;
};

export class FaultPolygonLayer extends BaseLayer<FaultPolygonLayerSettings, PolygonData_api[]> {
private _colorSet: ColorSet;

constructor(name: string, layerManager: LayerManager) {
const defaultSettings = {
ensembleIdent: null,
realizationNum: null,
polyline: {
polylineUtmXy: [],
actualSectionLengths: [],
},
polygonName: null,
attribute: null,
};
super(name, defaultSettings, layerManager);

this._colorSet = new ColorSet(defaultColorPalettes[0]);
}

getColorSet(): ColorSet {
return this._colorSet;
}

setColorSet(colorSet: ColorSet): void {
this._colorSet = colorSet;
this.notifySubscribers(LayerTopic.DATA);
}

private makeBoundingBox(): void {
if (!this._data) {
return;
}

const minX = Number.MAX_VALUE;
const maxX = Number.MIN_VALUE;
const minY = Number.MAX_VALUE;
const maxY = Number.MIN_VALUE;

super.setBoundingBox({
x: [minX, maxX],
y: [minY, maxY],
z: [0, 0],
});
}

getBoundingBox(): BoundingBox | null {
const bbox = super.getBoundingBox();
if (bbox) {
return bbox;
}

this.makeBoundingBox();
return super.getBoundingBox();
}

protected areSettingsValid(): boolean {
return (
this._settings.ensembleIdent !== null &&
this._settings.attribute !== null &&
this._settings.polygonName !== null &&
this._settings.realizationNum !== null
);
}

protected doSettingsChangesRequireDataRefetch(
prevSettings: FaultPolygonLayerSettings,
newSettings: FaultPolygonLayerSettings
): boolean {
return (
!isEqual(prevSettings.polygonName, newSettings.polygonName) ||
prevSettings.attribute !== newSettings.attribute ||
prevSettings.realizationNum !== newSettings.realizationNum ||
!isEqual(prevSettings.ensembleIdent, newSettings.ensembleIdent)
);
}

protected async fetchData(queryClient: QueryClient): Promise<PolygonData_api[]> {
// super.setBoundingBox(null);

const queryKey = [
"getPolygonsData",
this._settings.ensembleIdent?.getCaseUuid() ?? "",
this._settings.ensembleIdent?.getEnsembleName() ?? "",
this._settings.realizationNum ?? 0,
this._settings.polygonName ?? "",
this._settings.attribute ?? "",
];
this.registerQueryKey(queryKey);

return queryClient.fetchQuery({
queryKey,
queryFn: () =>
apiService.polygons.getPolygonsData(
this._settings.ensembleIdent?.getCaseUuid() ?? "",
this._settings.ensembleIdent?.getEnsembleName() ?? "",
this._settings.realizationNum ?? 0,
this._settings.polygonName ?? "",
this._settings.attribute ?? ""
),
staleTime: STALE_TIME,
gcTime: CACHE_TIME,
});
}
}

export function isFaultPolygonLayer(layer: BaseLayer<any, any>): layer is FaultPolygonLayer {
return layer instanceof FaultPolygonLayer;
}
5 changes: 4 additions & 1 deletion frontend/src/modules/2DViewer/layers/LayerFactory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LayerManager } from "@modules/_shared/layers/LayerManager";

import { FaultPolygonLayer } from "./FaultPolygonLayer";
import { PolygonLayer } from "./PolygonLayer";
import { SurfaceLayer } from "./SurfaceLayer";
import { WellboreLayer } from "./WellboreLayer";
Expand All @@ -12,8 +13,10 @@ export class LayerFactory {
return new SurfaceLayer("Surface", layerManager);
case LayerType.WELLBORE_SMDA:
return new WellboreLayer("Wells (Drilled)", layerManager);
case LayerType.FAULT_POLYGON:
return new FaultPolygonLayer("FaultPolygons", layerManager);
case LayerType.POLYGON:
return new PolygonLayer("Polygons", layerManager);
return new PolygonLayer("Field Outline", layerManager);
default:
throw new Error("Unknown layer type");
}
Expand Down
17 changes: 2 additions & 15 deletions frontend/src/modules/2DViewer/layers/PolygonLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ export type PolygonLayerSettings = {
realizationNum: number | null;
polygonName: string | null;
attribute: string | null;
color: string;
};

export class PolygonLayer extends BaseLayer<PolygonLayerSettings, PolygonData_api[]> {
private _colorSet: ColorSet;

constructor(name: string, layerManager: LayerManager) {
const defaultSettings = {
ensembleIdent: null,
Expand All @@ -32,21 +31,9 @@ export class PolygonLayer extends BaseLayer<PolygonLayerSettings, PolygonData_ap
},
polygonName: null,
attribute: null,
extensionLength: 0,
resolution: 1,
color: "#FF0000",
};
super(name, defaultSettings, layerManager);

this._colorSet = new ColorSet(defaultColorPalettes[0]);
}

getColorSet(): ColorSet {
return this._colorSet;
}

setColorSet(colorSet: ColorSet): void {
this._colorSet = colorSet;
this.notifySubscribers(LayerTopic.DATA);
}

private makeBoundingBox(): void {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/modules/2DViewer/layers/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
export enum LayerType {
SURFACE = "surface",
WELLBORE_SMDA = "wellbore_drilled",
FAULT_POLYGON = "fault_polygon",
POLYGON = "polygon",
}

export const LAYER_TYPE_TO_STRING_MAPPING = {
[LayerType.SURFACE]: "Surface",
[LayerType.WELLBORE_SMDA]: "Wells (Drilled)",
[LayerType.FAULT_POLYGON]: "Fault Polygons",
[LayerType.POLYGON]: "Polygons",
};
Loading

0 comments on commit 2ca6abf

Please sign in to comment.