From 754242cabf499718a779a95fe23fdd8a3215ef54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Mon, 2 Dec 2019 11:48:42 +0100 Subject: [PATCH] Reset internal attribution control cache when removing from map Fixes https://github.com/mapbox/mapbox-gl-js/issues/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 --- src/ui/control/attribution_control.js | 1 + test/unit/ui/control/attribution.test.js | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/ui/control/attribution_control.js b/src/ui/control/attribution_control.js index 09cfd9219eb..628148677fe 100644 --- a/src/ui/control/attribution_control.js +++ b/src/ui/control/attribution_control.js @@ -83,6 +83,7 @@ class AttributionControl { this._map.off('resize', this._updateCompact); this._map = (undefined: any); + this._attribHTML = (undefined: any); } _updateEditLink() { diff --git a/test/unit/ui/control/attribution.test.js b/test/unit/ui/control/attribution.test.js index 036f61cd204..0508f1609e4 100644 --- a/test/unit/ui/control/attribution.test.js +++ b/test/unit/ui/control/attribution.test.js @@ -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({