diff --git a/src/ui/control/attribution_control.js b/src/ui/control/attribution_control.js index ffa989d0b0f..a75a549a35d 100644 --- a/src/ui/control/attribution_control.js +++ b/src/ui/control/attribution_control.js @@ -146,18 +146,6 @@ class AttributionControl { _updateAttributions() { if (!this._map.style) return; let attributions: Array = []; - if (this.options.customAttribution) { - if (Array.isArray(this.options.customAttribution)) { - attributions = attributions.concat( - this.options.customAttribution.map(attribution => { - if (typeof attribution !== 'string') return ''; - return attribution; - }) - ); - } else if (typeof this.options.customAttribution === 'string') { - attributions.push(this.options.customAttribution); - } - } if (this._map.style.stylesheet) { const stylesheet: any = this._map.style.stylesheet; @@ -186,6 +174,14 @@ class AttributionControl { return true; }); + if (this.options.customAttribution) { + if (Array.isArray(this.options.customAttribution)) { + attributions = [...this.options.customAttribution, ...attributions]; + } else { + attributions.unshift(this.options.customAttribution); + } + } + // check if attribution string is different to minimize DOM changes const attribHTML = attributions.join(' | '); if (attribHTML === this._attribHTML) return; diff --git a/test/unit/ui/control/attribution.test.js b/test/unit/ui/control/attribution.test.js index 4aa9d0364cf..474948ac6af 100644 --- a/test/unit/ui/control/attribution.test.js +++ b/test/unit/ui/control/attribution.test.js @@ -237,7 +237,7 @@ test('AttributionControl shows all custom attributions if customAttribution arra t.equal( attributionControl._innerContainer.innerHTML, - 'Custom string | Another custom string | Some very long custom string' + 'Some very long custom string | Custom string | Another custom string' ); t.end(); });