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

feature: turn on all layers button #1571

Merged
merged 8 commits into from
Jan 30, 2023
1 change: 1 addition & 0 deletions css/svg/material-icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 41 additions & 1 deletion src/controls/legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const Legend = function Legend(options = {}) {
expanded = true,
contentCls,
contentStyle,
turnOnLayersControl = false,
name = 'legend',
labelOpacitySlider = '',
visibleLayersControl = false,
Expand Down Expand Up @@ -140,6 +141,22 @@ const Legend = function Legend(options = {}) {
});
};

const turnOnAllLayers = function turnOnAllLayers() {
const layers = viewer.getLayers();
layers.forEach((el) => {
if (!(['none', 'background'].includes(el.get('group')))) {
const group = viewer.getGroups().find((item) => item.name === el.get('group'));
if (typeof group !== 'undefined') {
if (!group.exclusive) {
el.setVisible(true);
}
} else {
el.setVisible(true);
}
}
});
};

const divider = El({
cls: 'divider margin-x-small',
style: {
Expand Down Expand Up @@ -222,6 +239,22 @@ const Legend = function Legend(options = {}) {
setVisibleLayersViewActive(!visibleLayersViewActive);
};

const turnOnLayersButton = Button({
cls: 'round compact icon-small margin-x-smaller',
title: 'Tänd alla lager utom bakgrundslager',
click() {
viewer.dispatch('active:turnonlayers');
},
style: {
'align-self': 'center',
'padding-right': '6px'
},
icon: '#ic_visibility_24px',
iconStyle: {
fill: '#7a7a7a'
}
});

const layerSearchInput = Input({
cls: 'o-search-layer-field placeholder-text-smaller smaller',
style: { height: '1.5rem', margin: 0, width: '100%' },
Expand Down Expand Up @@ -457,7 +490,12 @@ const Legend = function Legend(options = {}) {
},
onAdd(evt) {
viewer = evt.target;
viewer.on('active:turnofflayers', turnOffAllLayers);
if (turnOffLayersControl) {
viewer.on('active:turnofflayers', turnOffAllLayers);
}
if (turnOnLayersControl) {
viewer.on('active:turnonlayers', turnOnAllLayers);
}
viewer.on('active:togglevisibleLayers', toggleShowVisibleLayers);

const backgroundLayers = viewer.getLayersByProperty('group', 'background').reverse();
Expand All @@ -479,8 +517,10 @@ const Legend = function Legend(options = {}) {
},
onRender() {
const layerControlCmps = [];
if (turnOnLayersControl) layerControlCmps.push(turnOnLayersButton);
if (turnOffLayersControl) layerControlCmps.push(turnOffLayersButton);
const layerControl = El({
cls: 'grow flex justify-end align-center no-shrink',
components: layerControlCmps
});
mainContainerEl = document.getElementById(mainContainerCmp.getId());
Expand Down
2 changes: 1 addition & 1 deletion src/controls/legend/overlays.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Overlays = function Overlays(options) {

const cls = `${clsSettings} o-layerswitcher-overlays flex row overflow-hidden`.trim();
const style = dom.createStyle({
width: '220px', height: '100%', 'min-width': '220px', ...styleSettings
width: '100%', height: '100%', 'min-width': '220px', ...styleSettings
});
const nonGroupNames = ['background', 'none'];
const rootGroupNames = ['root', '', null, undefined];
Expand Down