Skip to content

Commit

Permalink
New take
Browse files Browse the repository at this point in the history
  • Loading branch information
jokd committed Dec 17, 2024
1 parent e0b79d6 commit 33d27e9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/controls/legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ const Legend = function Legend(options = {}) {
components: mainContainerComponents,
style: {
'max-height': `${maxHeight}px`,
width: 'min-content'
'min-width': '220px'
}
});

Expand Down
16 changes: 12 additions & 4 deletions src/controls/legend/overlays.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,18 @@ const Overlays = function Overlays(options) {

// Hide overlays container when empty
const onChangeLayer = function onChangeLayer() {
const oldNrOverlays = overlays.length;
const nrOverlays = readOverlays().length;
if (oldNrOverlays !== nrOverlays && nrOverlays < 2 && oldNrOverlays < 2) {
document.getElementById(this.getId()).classList.toggle('hidden');
const legend = viewer.getControlByName('legend');
const state = legend.getState();
if (!state.visibleLayersViewActive) {
const oldNrOverlays = overlays.length;

Check failure on line 139 in src/controls/legend/overlays.js

View workflow job for this annotation

GitHub Actions / lint

'oldNrOverlays' is assigned a value but never used
const nrOverlays = readOverlays().length;
if (nrOverlays === 0) {
document.getElementById(this.getId()).classList.add('hidden');
} else {
if (!state.visibleLayersViewActive) {

Check failure on line 144 in src/controls/legend/overlays.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected if as the only statement in an else block
document.getElementById(this.getId()).classList.remove('hidden');
}
}
}
};

Expand Down
6 changes: 5 additions & 1 deletion src/controls/legend/visibleOverlays.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@ const Overlays = function Overlays(options) {
});
readOverlays();
overlays.forEach(overlay => {
if (!existing.find(eOverlay => eOverlay.name === overlay.name)) {
const exist = existing.find(eOverlay => eOverlay.name === (overlay.name || overlay.get('name')));
if (!exist) {
addLayer(overlay, { position: 'bottom' });
} else {
document.getElementById(exist.getId()).classList.remove('hidden');
}
});

Expand All @@ -142,6 +145,7 @@ const Overlays = function Overlays(options) {
this.on('readOverlays', () => {
updateVisibleOverlays();
});
viewer.getMap().getLayers().on('add', updateVisibleOverlays.bind(this));
},
hasOverlays,
onRender() {
Expand Down

0 comments on commit 33d27e9

Please sign in to comment.