Skip to content

Commit

Permalink
🎨 Handle output data error to manage query by control
Browse files Browse the repository at this point in the history
  • Loading branch information
volterra79 committed Dec 19, 2024
1 parent 0bdc178 commit 9ae00cb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/map/controls/queryby.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export class QueryBy extends InteractionControl {
this.types.forEach(t => {
CONTROLS[t].toggle(false);
CONTROLS[t].autorun = false;
CONTROLS['queryby'].element.classList.toggle('ol-' + t, t === this.types[0]);
CONTROLS['queryby'].element.classList.toggle(`ol-${t}`, t === this.types[0]);
CONTROLS[t].layers.forEach(l => l.setTocHighlightable(false));
});
}
Expand Down Expand Up @@ -584,6 +584,12 @@ export class QueryBy extends InteractionControl {
}

async runSpatialQuery(type) {
//@since 3.11.0 In case of error error-output-data set to true and not autorun is set
let error = false;
const setError = () => { error = true; this.toggle(); };

GUI.once('error-output-data', setError);

try {

const control = CONTROLS[type];
Expand Down Expand Up @@ -653,12 +659,16 @@ export class QueryBy extends InteractionControl {
});
}

control.autorun = true;
//set autorun to true if no error happensd
control.autorun = !error;

} catch(e) {
console.warn('Error running spatial query: ', e);
}

//remove handler to error-output-data event
GUI.off('error-output-data', setError);

}

}
Expand Down
2 changes: 2 additions & 0 deletions src/services/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ export default new (class GUI extends G3WObject {
message: errorToMessage(e),
textMessage: true
});
//@scince 3.11.0 emit error-output-data
this.emit('error-output-data', e);
await this.closeContent();
}

Expand Down

0 comments on commit 9ae00cb

Please sign in to comment.