diff --git a/src/controls/legend/overlay.js b/src/controls/legend/overlay.js index 6b0a97ce9..d5eec06f6 100644 --- a/src/controls/legend/overlay.js +++ b/src/controls/legend/overlay.js @@ -19,7 +19,6 @@ const OverlayLayer = function OverlayLayer(options) { let headerIconClass = headerIconCls; const popupMenuItems = []; - let layerList; const hasStylePicker = viewer.getLayerStylePicker(layer).length > 0; const layerIconCls = `round compact icon-small relative no-shrink light ${hasStylePicker ? 'style-picker' : ''}`; @@ -223,8 +222,9 @@ const OverlayLayer = function OverlayLayer(options) { onRender() { const labelEl = document.getElementById(this.getId()); labelEl.addEventListener('click', (e) => { - layerList.removeOverlay(layer.get('name')); - viewer.getMap().removeLayer(layer); + if (window.confirm('Vill du radera lagret?')) { + viewer.getMap().removeLayer(layer); + } e.preventDefault(); }); }, @@ -330,7 +330,6 @@ const OverlayLayer = function OverlayLayer(options) { this.on('clear', onRemove.bind(this)); }, onAdd(evt) { - layerList = evt.target; const parentEl = document.getElementById(evt.target.getId()); const htmlString = this.render(); const el = dom.html(htmlString); diff --git a/src/controls/legend/overlays.js b/src/controls/legend/overlays.js index c616e7fc2..5fd609933 100644 --- a/src/controls/legend/overlays.js +++ b/src/controls/legend/overlays.js @@ -206,7 +206,7 @@ const Overlays = function Overlays(options) { const layer = evt.element; const layerName = layer.get('name'); const groupName = layer.get('group'); - if (groupName) { + if (groupName && groupName !== 'root') { const groupCmp = groupCmps.find((cmp) => cmp.name === groupName); if (groupCmp) { groupCmp.removeOverlay(layerName); @@ -214,7 +214,7 @@ const Overlays = function Overlays(options) { document.getElementById(groupCmp.getId()).classList.add('hidden'); } } - } else { + } else if (groupName === 'root') { rootGroup.removeOverlay(layerName); } };