Skip to content

Commit

Permalink
Reset internal attribution control cache when removing from map (#9052)
Browse files Browse the repository at this point in the history
Fixes #9051.

When creating an attribution control, we're caching the HTML string in the AttributionControl object. That cache wasn't reset when the control was removed from the map. Upon re-adding, we incorrectly assumed that the HTML was already up-to-date because our internal cache said so. This patch fixes it by clearing the internal cache so that attribution shows up properly when re-adding the control.

h/t @cs09g
  • Loading branch information
kkaefer authored and ansis committed Dec 4, 2019
1 parent 65b3fa0 commit 43cd834
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ui/control/attribution_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class AttributionControl {
this._map.off('resize', this._updateCompact);

this._map = (undefined: any);
this._attribHTML = (undefined: any);
}

_updateEditLink() {
Expand Down
13 changes: 13 additions & 0 deletions test/unit/ui/control/attribution.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ test('AttributionControl shows custom attribution if customAttribution option is
t.end();
});

test('AttributionControl shows custom attribution if customAttribution option is provided, control is removed and added back', (t) => {
const map = createMap(t);
const attributionControl = new AttributionControl({
customAttribution: 'Custom string'
});
map.addControl(attributionControl);
map.removeControl(attributionControl);
map.addControl(attributionControl);

t.equal(attributionControl._innerContainer.innerHTML, 'Custom string');
t.end();
});

test('AttributionControl in compact mode shows custom attribution if customAttribution option is provided', (t) => {
const map = createMap(t);
const attributionControl = new AttributionControl({
Expand Down

0 comments on commit 43cd834

Please sign in to comment.