Skip to content

Commit

Permalink
feat: confirm removal of layer
Browse files Browse the repository at this point in the history
Fixes #1674
Setting "confirmRemoval": true pops up a confirm dialog window
This commit also includes also removes redundant calls to removeOverlay-method and relies on the event instead.
  • Loading branch information
jokd committed Feb 8, 2023
1 parent 469a3f6 commit 81c1d73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/controls/legend/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' : ''}`;
Expand Down Expand Up @@ -223,9 +222,14 @@ 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);
e.preventDefault();
let doRemove = true;
if (layer.get('confirmRemoval')) {
doRemove = window.confirm('Vill du radera lagret?');
}
if (doRemove) {
viewer.getMap().removeLayer(layer);
e.preventDefault();
}
});
},
render() {
Expand Down Expand Up @@ -330,7 +334,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);
Expand Down
4 changes: 2 additions & 2 deletions src/controls/legend/overlays.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@ 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);
if (emptyGroupCheck(groupName)) {
document.getElementById(groupCmp.getId()).classList.add('hidden');
}
}
} else {
} else if (groupName === 'root') {
rootGroup.removeOverlay(layerName);
}
};
Expand Down

0 comments on commit 81c1d73

Please sign in to comment.