Skip to content

Commit

Permalink
Turn on all layers button
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyblasta committed Jul 18, 2022
1 parent 4bdb6de commit 9f9ce6d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
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.
49 changes: 39 additions & 10 deletions 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 @@ -132,6 +133,15 @@ const Legend = function Legend(options = {}) {
});
};

const turnOnAllLayers = function turnOnAllLayers() {
const layers = viewer.getLayers();
layers.forEach((el) => {
if (!(['none', 'background'].includes(el.get('group')))) {
el.setVisible(true);
}
});
};

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

const turnOnLayersButton = Button({
cls: 'round compact icon-small margin-x-smaller',
title: 'Tänd alla lager',
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 @@ -423,12 +449,14 @@ const Legend = function Legend(options = {}) {
restoreState(params);
},
getuseGroupIndication() { return useGroupIndication; },
addButtonToTools(button) {
addButtonToTools(button, addDiveder = true) {
const toolsEl = document.getElementById(toolsCmp.getId());
toolsEl.classList.remove('hidden');
if (toolsCmp.getComponents().length > 0) {
toolsEl.style.justifyContent = 'space-between';
toolsEl.insertBefore(dom.html(divider.render()), toolsEl.firstChild);
toolsEl.style.justifyContent = 'right';
if (addDiveder) {
toolsEl.insertBefore(dom.html(divider.render()), toolsEl.firstChild);
}
toolsEl.insertBefore(dom.html(button.render()), toolsEl.firstChild);
} else {
toolsEl.appendChild(dom.html(button.render()));
Expand All @@ -441,7 +469,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 @@ -456,11 +489,6 @@ const Legend = function Legend(options = {}) {
viewer.getMap().on('click', onMapClick);
},
onRender() {
const layerControlCmps = [];
if (turnOffLayersControl) layerControlCmps.push(turnOffLayersButton);
const layerControl = El({
components: layerControlCmps
});
mainContainerEl = document.getElementById(mainContainerCmp.getId());
layerButtonEl = document.getElementById(layerButton.getId());
layerSwitcherEl.addEventListener('collapse:toggle', (e) => {
Expand All @@ -469,7 +497,8 @@ const Legend = function Legend(options = {}) {
toggleVisibility();
});
window.addEventListener('resize', updateMaxHeight);
if (layerControlCmps.length > 0) this.addButtonToTools(layerControl);
if (turnOffLayersControl) this.addButtonToTools(turnOffLayersButton, false);
if (turnOnLayersControl) this.addButtonToTools(turnOnLayersButton, false);
if (searchLayersControl) this.addButtonToTools(layerSearchInput);
initAutocomplete();
bindUIActions();
Expand Down

0 comments on commit 9f9ce6d

Please sign in to comment.