Skip to content

Commit

Permalink
feature: confirm removal of layer (#1675)
Browse files Browse the repository at this point in the history
* feat: confirm removal of layer

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.

* Update overlay.js
  • Loading branch information
jokd authored Feb 22, 2023
1 parent e3e5290 commit e6aa4be
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 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,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();
});
},
Expand Down Expand Up @@ -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);
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 e6aa4be

Please sign in to comment.