Skip to content

Commit

Permalink
patch: Improve "isLoadedCallback" to not return true before first dra…
Browse files Browse the repository at this point in the history
…w of layer not only just when data are loaded.
  • Loading branch information
nilscb committed Sep 15, 2023
1 parent 77ea355 commit 5e41d9a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,17 @@ const defaultProps = {

// This is a private layer used only by the composite Map3DLayer
export default class privateLayer extends Layer<privateLayerProps> {
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({
Expand Down Expand Up @@ -254,6 +261,10 @@ export default class privateLayer extends Layer<privateLayerProps> {
if (!this.props.depthTest) {
gl.enable(gl.DEPTH_TEST);
}

if (!this.state["isLoaded"]) {
this.setState({ ...this.state, isLoaded: true });
}
}

decodePickingColor(): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,19 @@ const defaultProps = {

// This is a private layer used only by the composite Map3DLayer
export default class privateMapLayer extends Layer<privateMapLayerProps> {
get isLoaded(): boolean {
console.log("isLoaded function")
return this.state["isLoaded"] ?? false;
}

initializeState(context: DeckGLLayerContext): void {
console.log("initializeState")
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({
Expand Down Expand Up @@ -193,6 +202,7 @@ export default class privateMapLayer extends Layer<privateMapLayerProps> {
// Signature from the base class, eslint doesn't like the any type.
// eslint-disable-next-line
draw(args: any): void {
console.log("draw")
if (!this.state["models"]) {
return;
}
Expand Down Expand Up @@ -277,6 +287,10 @@ export default class privateMapLayer extends Layer<privateMapLayerProps> {
if (this.props.gridLines) {
mesh_lines_model.draw();
}

if (!this.state["isLoaded"]) {
this.setState({ ...this.state, isLoaded: true });
}
}

decodePickingColor(): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@ const defaultProps = {

// This is a private layer used only by the composite TriangleLayer
export default class PrivateTriangleLayer extends Layer<PrivateTriangleLayerProps> {
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({
Expand Down Expand Up @@ -166,6 +170,10 @@ export default class PrivateTriangleLayer extends Layer<PrivateTriangleLayerProp
if (!this.props.depthTest) {
gl.enable(GL.DEPTH_TEST);
}

if (!this.state["isLoaded"]) {
this.setState({ ...this.state, isLoaded: true });
}
}

decodePickingColor(): number {
Expand Down

0 comments on commit 5e41d9a

Please sign in to comment.