From 3875f8b55a7d2abf34dca7a82079b602f2741de0 Mon Sep 17 00:00:00 2001 From: nilscb Date: Fri, 15 Sep 2023 12:42:42 +0200 Subject: [PATCH] fix: Improve "isLoadedCallback" to not return true before first draw of layer not only just when data are loaded. (#1656) --- .../src/layers/grid3d/privateLayer.ts | 13 ++++++++++++- .../src/layers/map/privateMapLayer.ts | 13 ++++++++++++- .../src/layers/triangle/privateTriangleLayer.ts | 10 +++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/typescript/packages/subsurface-viewer/src/layers/grid3d/privateLayer.ts b/typescript/packages/subsurface-viewer/src/layers/grid3d/privateLayer.ts index b3de38122..5a8638fe2 100644 --- a/typescript/packages/subsurface-viewer/src/layers/grid3d/privateLayer.ts +++ b/typescript/packages/subsurface-viewer/src/layers/grid3d/privateLayer.ts @@ -115,10 +115,17 @@ const defaultProps = { // This is a private layer used only by the composite Map3DLayer export default class privateLayer extends Layer { + get isLoaded(): boolean { + return this.state["isLoaded"] ?? false; + } + initializeState(context: DeckGLLayerContext): void { const { gl } = context; const [model_mesh, mesh_lines_model] = this._getModels(gl); - this.setState({ models: [model_mesh, mesh_lines_model] }); + this.setState({ + models: [model_mesh, mesh_lines_model], + isLoaded: false, + }); } shouldUpdateState({ @@ -254,6 +261,10 @@ export default class privateLayer extends Layer { if (!this.props.depthTest) { gl.enable(gl.DEPTH_TEST); } + + if (!this.state["isLoaded"]) { + this.setState({ ...this.state, isLoaded: true }); + } } decodePickingColor(): number { diff --git a/typescript/packages/subsurface-viewer/src/layers/map/privateMapLayer.ts b/typescript/packages/subsurface-viewer/src/layers/map/privateMapLayer.ts index 28eec1bdb..3fa0247a4 100644 --- a/typescript/packages/subsurface-viewer/src/layers/map/privateMapLayer.ts +++ b/typescript/packages/subsurface-viewer/src/layers/map/privateMapLayer.ts @@ -129,10 +129,17 @@ const defaultProps = { // This is a private layer used only by the composite Map3DLayer export default class privateMapLayer extends Layer { + get isLoaded(): boolean { + return this.state["isLoaded"] ?? false; + } + initializeState(context: DeckGLLayerContext): void { const { gl } = context; const [model_mesh, mesh_lines_model] = this._getModels(gl); - this.setState({ models: [model_mesh, mesh_lines_model] }); + this.setState({ + models: [model_mesh, mesh_lines_model], + isLoaded: false, + }); } shouldUpdateState({ @@ -277,6 +284,10 @@ export default class privateMapLayer extends Layer { if (this.props.gridLines) { mesh_lines_model.draw(); } + + if (!this.state["isLoaded"]) { + this.setState({ ...this.state, isLoaded: true }); + } } decodePickingColor(): number { diff --git a/typescript/packages/subsurface-viewer/src/layers/triangle/privateTriangleLayer.ts b/typescript/packages/subsurface-viewer/src/layers/triangle/privateTriangleLayer.ts index 20b492adb..0ed92aac9 100644 --- a/typescript/packages/subsurface-viewer/src/layers/triangle/privateTriangleLayer.ts +++ b/typescript/packages/subsurface-viewer/src/layers/triangle/privateTriangleLayer.ts @@ -72,10 +72,14 @@ const defaultProps = { // This is a private layer used only by the composite TriangleLayer export default class PrivateTriangleLayer extends Layer { + get isLoaded(): boolean { + return this.state["isLoaded"] ?? false; + } + initializeState(context: DeckGLLayerContext): void { const { gl } = context; const [triangleModel, lineMode] = this._getModels(gl); - this.setState({ models: [triangleModel, lineMode] }); + this.setState({ models: [triangleModel, lineMode], isLoaded: false }); } shouldUpdateState({ @@ -166,6 +170,10 @@ export default class PrivateTriangleLayer extends Layer