Skip to content

Commit

Permalink
Allow setting order of custom attribution (#11196)
Browse files Browse the repository at this point in the history
* removed sorting attributions

* Substring duplicate removal still needed, moved added custom attributions after checking source attributions

* fixed unit test to correspond with order of custom attribution

* fixed unit test fail

* fixed reversing original array

* simplified string checking

* Removing unneeded string type filtering
  • Loading branch information
avpeery authored Nov 10, 2021
1 parent b50c94a commit 1c7fc64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
20 changes: 8 additions & 12 deletions src/ui/control/attribution_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,6 @@ class AttributionControl {
_updateAttributions() {
if (!this._map.style) return;
let attributions: Array<string> = [];
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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ui/control/attribution.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down

0 comments on commit 1c7fc64

Please sign in to comment.