From 09a1dd43c6769fc31c728a94ca425cc3747c5f98 Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Mon, 28 Sep 2020 14:05:23 +0100 Subject: [PATCH 1/2] reset to collapsible when no uncollapsible sources --- src/ol/control/Attribution.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ol/control/Attribution.js b/src/ol/control/Attribution.js index 12eb3c570d..733f5c2a46 100644 --- a/src/ol/control/Attribution.js +++ b/src/ol/control/Attribution.js @@ -175,6 +175,7 @@ class Attribution extends Control { */ const visibleAttributions = []; + let collapsible = true; const layerStatesArray = frameState.layerStatesArray; for (let i = 0, ii = layerStatesArray.length; i < ii; ++i) { const layerState = layerStatesArray[i]; @@ -197,12 +198,8 @@ class Attribution extends Control { continue; } - if ( - !this.overrideCollapsible_ && - source.getAttributionsCollapsible() === false - ) { - this.setCollapsible(false); - } + collapsible = + collapsible && source.getAttributionsCollapsible() !== false; if (Array.isArray(attributions)) { for (let j = 0, jj = attributions.length; j < jj; ++j) { @@ -218,6 +215,9 @@ class Attribution extends Control { } } } + if (!this.overrideCollapsible_) { + this.setCollapsible(collapsible); + } return visibleAttributions; } From cb77784d2ae73c8f85babc5b058eb7524300d050 Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Wed, 30 Sep 2020 10:36:53 +0100 Subject: [PATCH 2/2] also restore collapsed state to last user setting --- src/ol/control/Attribution.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ol/control/Attribution.js b/src/ol/control/Attribution.js index 733f5c2a46..682e153021 100644 --- a/src/ol/control/Attribution.js +++ b/src/ol/control/Attribution.js @@ -66,6 +66,12 @@ class Attribution extends Control { this.collapsed_ = options.collapsed !== undefined ? options.collapsed : true; + /** + * @private + * @type {boolean} + */ + this.userCollapsed_ = this.collapsed_; + /** * @private * @type {boolean} @@ -265,6 +271,7 @@ class Attribution extends Control { handleClick_(event) { event.preventDefault(); this.handleToggle_(); + this.userCollapsed_ = this.collapsed_; } /** @@ -300,7 +307,7 @@ class Attribution extends Control { } this.collapsible_ = collapsible; this.element.classList.toggle('ol-uncollapsible'); - if (!collapsible && this.collapsed_) { + if (this.userCollapsed_) { this.handleToggle_(); } } @@ -313,6 +320,7 @@ class Attribution extends Control { * @api */ setCollapsed(collapsed) { + this.userCollapsed_ = collapsed; if (!this.collapsible_ || this.collapsed_ === collapsed) { return; }