From 9f9ce6d5f4ccede4bf991aadbffb5510f92dc8ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bl=C3=A4sta=20Johnny?= Date: Mon, 18 Jul 2022 13:44:11 +0200 Subject: [PATCH] Turn on all layers button --- css/svg/material-icons.svg | 1 + src/controls/legend.js | 49 ++++++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/css/svg/material-icons.svg b/css/svg/material-icons.svg index 9fb5acd56..50be751cb 100644 --- a/css/svg/material-icons.svg +++ b/css/svg/material-icons.svg @@ -13,6 +13,7 @@ + diff --git a/src/controls/legend.js b/src/controls/legend.js index 83468a338..2e4af93e6 100644 --- a/src/controls/legend.js +++ b/src/controls/legend.js @@ -15,6 +15,7 @@ const Legend = function Legend(options = {}) { expanded = true, contentCls, contentStyle, + turnOnLayersControl = false, name = 'legend', labelOpacitySlider = '', visibleLayersControl = false, @@ -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: { @@ -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%' }, @@ -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())); @@ -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(); @@ -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) => { @@ -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();