Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exclusive layers in legend search #1621

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/controls/legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const Legend = function Legend(options = {}) {
const addBackgroundButton = function addBackgroundButton(layer) {
const styleName = layer.get('styleName') || 'default';
const icon = viewer.getStyle(styleName) ? imageSource(viewer.getStyle(styleName)) : 'img/png/farg.png';
backgroundLayerButtons.push(Button({
const backgroundLayerButton = Button({
icon,
cls: 'round smallest border icon-small icon-bg',
title: layer.get('title'),
Expand All @@ -101,7 +101,15 @@ const Legend = function Legend(options = {}) {
}
}
}
}));
});
layer.on('change:visible', () => {
if (layer.getVisible() === true) {
backgroundLayerButton.setState('active');
} else {
backgroundLayerButton.setState('initial');
}
});
backgroundLayerButtons.push(backgroundLayerButton);
};

const addBackgroundButtons = function addBackgroundButtons(layers) {
Expand Down Expand Up @@ -260,6 +268,12 @@ const Legend = function Legend(options = {}) {
if (name) {
// Todo
const layer = viewer.getLayer(label);
const layerGroup = layer.get('group');
const groupExclusive = (viewer.getGroup(layerGroup) && (viewer.getGroup(layerGroup).exclusive || viewer.getGroup(layerGroup).name === 'background'));
if (groupExclusive) {
const layers = viewer.getLayersByProperty('group', layerGroup);
layers.forEach(l => l.setVisible(false));
}
layer.setVisible(true);
document.getElementsByClassName('o-search-layer-field')[0].value = '';
} else {
Expand Down