Skip to content

Commit

Permalink
Extract method
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Oct 4, 2024
1 parent 15cfe04 commit 84884e0
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions client/src/components/MapView/LayerControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class LayerControl implements IControl {
if (meta.group) {
groupName = meta.group;
}
console.log(groupName);

const layerDiv = document.createElement('div');
layerDiv.className = 'layer';
Expand Down Expand Up @@ -74,29 +73,7 @@ class LayerControl implements IControl {
const g = groups.get(groupName);
g?.appendChild(layerDiv);
} else {
const groupDiv = document.createElement('div');
groupDiv.className = 'group';

const groupInput = document.createElement('input');
groupInput.onchange = () => {
groupDiv.querySelectorAll('input.layer').forEach((i) => {
const input = i as HTMLInputElement;
input.checked = groupInput.checked;
var event = new Event('change');
i.dispatchEvent(event);
});
};
groupInput.type = 'checkbox';
groupInput.id = groupName;

const groupLabel = document.createElement('label');
groupLabel.textContent = groupName;
groupLabel.htmlFor = groupName;
groupLabel.className = 'group-label';

groupDiv.appendChild(groupInput);
groupDiv.appendChild(groupLabel);
groupDiv.appendChild(layerDiv);
const groupDiv = this.buildgGroupDiv(groupName, layerDiv);
groups.set(groupName, groupDiv);
this.container.appendChild(groupDiv);
}
Expand All @@ -107,6 +84,33 @@ class LayerControl implements IControl {
return this.container;
}

private buildgGroupDiv(groupName: string, layerDiv: HTMLDivElement) {
const groupDiv = document.createElement('div');
groupDiv.className = 'group';

const groupInput = document.createElement('input');
groupInput.onchange = () => {
groupDiv.querySelectorAll('input.layer').forEach((i) => {
const input = i as HTMLInputElement;
input.checked = groupInput.checked;
var event = new Event('change');

Check failure on line 96 in client/src/components/MapView/LayerControl.tsx

View workflow job for this annotation

GitHub Actions / debug-client

Unexpected var, use let or const instead
i.dispatchEvent(event);
});
};
groupInput.type = 'checkbox';
groupInput.id = groupName;

const groupLabel = document.createElement('label');
groupLabel.textContent = groupName;
groupLabel.htmlFor = groupName;
groupLabel.className = 'group-label';

groupDiv.appendChild(groupInput);
groupDiv.appendChild(groupLabel);
groupDiv.appendChild(layerDiv);
return groupDiv;
}

private layerVisible(map: WebMap, layer: { id: string }) {
return map.getLayoutProperty(layer.id, 'visibility') !== 'none';
}
Expand Down

0 comments on commit 84884e0

Please sign in to comment.