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

feature: Remove subgroup from menu #2096

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

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
Loading