Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove layertree submenu when changing theme #5516

Merged
merged 1 commit into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions contribs/gmf/src/layertree/TreeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ LayertreeTreeManager.prototype.handleThemesChange_ = function() {
* @return {boolean} True if the group has been added. False otherwise.
*/
LayertreeTreeManager.prototype.setFirstLevelGroups = function(firstLevelGroups) {
//Remove existing submenu if opened at theme refresh
this.parseTreeNodes(this.root);

this.root.children.length = 0;
this.ngeoStateManager_.deleteParam(PermalinkParam.TREE_GROUPS);
return this.addFirstLevelGroups(firstLevelGroups);
Expand Down Expand Up @@ -232,6 +235,35 @@ LayertreeTreeManager.prototype.setInitialFirstLevelGroups = function(firstGroups
this.initialLevelFirstGroups_ = firstGroups;
};

/**
* @param {import('gmf/themes.js').GmfGroup | import('gmf/themes.js').GmfLayer | import('gmf/themes.js').GmfRootNode} node Layer tree node to remove.
*/
LayertreeTreeManager.prototype.parseTreeNodes = function(node) {
if (node.children) {
/**
* @param {any} child
*/
node.children.forEach(child => {
this.parseTreeNodes(child);
});
}
if (node.popupId) {
this.removePopup_(node);
}
};


/**
* @param {import('gmf/themes.js').GmfGroup} node Layer tree node to remove.
* @private
*/
LayertreeTreeManager.prototype.removePopup_ = function(node) {
const popupId = node.popupId;
$(`#${popupId}`).remove();
delete node.popupId;
};


/**
* @param {array} array An array of groups.
* @param {number} old_index The old index before reorder (the current one).
Expand Down
33 changes: 2 additions & 31 deletions contribs/gmf/src/layertree/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,46 +802,17 @@ Controller.prototype.tagPopup = function(node) {
* @param {import('gmf/themes.js').GmfGroup} node Layer tree node to remove.
*/
Controller.prototype.removeNode = function(node) {
this.parseTreeNodes(node);
this.gmfTreeManager_.parseTreeNodes(node);
this.gmfTreeManager_.removeGroup(node);
};


Controller.prototype.removeAllNodes = function() {
this.parseTreeNodes(this.root);
this.gmfTreeManager_.parseTreeNodes(this.root);
this.gmfTreeManager_.removeAll();
};


/**
* @param {import('gmf/themes.js').GmfGroup | import('gmf/themes.js').GmfLayer | import('gmf/themes.js').GmfRootNode} node Layer tree node to remove.
*/
Controller.prototype.parseTreeNodes = function(node) {
if (node.children) {
/**
* @param {any} child
*/
node.children.forEach(child => {
this.parseTreeNodes(child);
});
}
if (node.popupId) {
this.removePopup_(node);
}
};


/**
* @param {import('gmf/themes.js').GmfGroup} node Layer tree node to remove.
* @private
*/
Controller.prototype.removePopup_ = function(node) {
const popupId = node.popupId;
$(`#${popupId}`).remove();
delete node.popupId;
};


/**
* @return {number} first level node count.
*/
Expand Down