Skip to content

Commit

Permalink
Remove subgroup from menu
Browse files Browse the repository at this point in the history
  • Loading branch information
jokd committed Dec 6, 2024
1 parent 1872642 commit 69a2f38
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/controls/legend/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const Group = function Group(viewer, options = {}) {
draggable = false,
zIndexStart = 0.1,
opacityControl = false,
removable = false,
zoomToExtent = false,
description
} = options;
Expand Down Expand Up @@ -78,7 +79,7 @@ const Group = function Group(viewer, options = {}) {
}
}) : false;

const moreInfoButton = (opacityControl || zoomToExtent || description || (abstract && !showAbstractInLegend)) ? createMoreInfoButton({ viewer,
const moreInfoButton = (opacityControl || removable || zoomToExtent || description || (abstract && !showAbstractInLegend)) ? createMoreInfoButton({ viewer,
group: thisGroup }) : false;

const SubGroupHeader = function SubGroupHeader() {
Expand Down
24 changes: 23 additions & 1 deletion src/controls/legend/moreinfobutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function createMoreInfoButton(params) {
const popupMenuItems = [];
let moreInfoButton;
let popupMenu;
const showPopup = group.zoomToExtent && group.extent; // In case of zoomToExtent we always want to show popupmenu
const showPopup = group.zoomToExtent && group.extent || group.removable; // In case of zoomToExtent or removable we always want to show popupmenu

Check failure on line 14 in src/controls/legend/moreinfobutton.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected mix of '&&' and '||'. Use parentheses to clarify the intended order of operations

Check failure on line 14 in src/controls/legend/moreinfobutton.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected mix of '&&' and '||'. Use parentheses to clarify the intended order of operations

const eventOverlayProps = new CustomEvent('overlayproperties', {
bubbles: true,
Expand Down Expand Up @@ -135,6 +135,28 @@ export default function createMoreInfoButton(params) {
popupMenuItems.push(removeLayerMenuItem);
}

if (group && group.removable) {
const removeGroupMenuItem = Component({
onRender() {
const labelEl = document.getElementById(this.getId());
labelEl.addEventListener('click', (e) => {
const doRemove = (group.promptlessRemoval === true) || window.confirm('Vill du radera gruppen?');
if (doRemove) {
viewer.removeGroup(group.name);
e.preventDefault();
e.stopPropagation();
}
popupMenu.setVisibility(false);
});
},
render() {
const labelCls = 'text-smaller padding-x-small grow pointer no-select overflow-hidden';
return `<li id="${this.getId()}" class="${labelCls}">Ta bort grupp</li>`;
}
});
popupMenuItems.push(removeGroupMenuItem);
}

const popupMenuList = Component({
onInit() {
this.addComponents(popupMenuItems);
Expand Down

0 comments on commit 69a2f38

Please sign in to comment.