Skip to content

Commit

Permalink
Remove non needed datacontroller check
Browse files Browse the repository at this point in the history
Remove layer group only if defined
  • Loading branch information
ivmartel committed Feb 18, 2025
1 parent e989d89 commit 684fcf4
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/app/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ export class App {
* @param {string} divId The div id.
*/
removeDataViewConfig(dataId, divId) {
// remove from list
// input checks
const configs = this.#options.dataViewConfigs;
if (typeof configs[dataId] === 'undefined') {
// no config for dataId
Expand All @@ -1035,31 +1035,29 @@ export class App {
// no config for divId
return;
}

// remove from config list
configs[dataId].splice(itemIndex, 1);
if (configs[dataId].length === 0) {
delete configs[dataId];
}

const lg = this.#stage.getLayerGroupByDivId(divId);
// data is loaded, remove view
if (typeof this.#dataController.get(dataId) !== 'undefined') {
if (typeof lg !== 'undefined') {
const vls = lg.getViewLayersByDataId(dataId);
if (vls.length === 1) {
lg.removeLayer(vls[0]);
}
const dls = lg.getDrawLayersByDataId(dataId);
if (dls.length === 1) {
lg.removeLayer(dls[0]);
}
if (vls.length === 0 && dls.length === 0) {
throw new Error('Expected one layer, got none');
}

// update layer group
const layerGroup = this.#stage.getLayerGroupByDivId(divId);
if (typeof layerGroup !== 'undefined') {
// remove layer if possible
const vls = layerGroup.getViewLayersByDataId(dataId);
if (vls.length === 1) {
layerGroup.removeLayer(vls[0]);
}
const dls = layerGroup.getDrawLayersByDataId(dataId);
if (dls.length === 1) {
layerGroup.removeLayer(dls[0]);
}
// remove layer group if empty
if (layerGroup.getNumberOfLayers() === 0) {
this.#stage.removeLayerGroup(layerGroup);
}
}
if (lg.getNumberOfLayers() === 0) {
this.#stage.removeLayerGroup(lg);
}
}

Expand Down

0 comments on commit 684fcf4

Please sign in to comment.