From 262a48c4c55515e009704baf20a9eee0d95f61c2 Mon Sep 17 00:00:00 2001 From: Andrew Harvey Date: Wed, 10 Nov 2021 14:00:10 +1100 Subject: [PATCH] ensure style is updated when control is added after the style is already loaded `map.on('style.load')` is only called if registered before the style resource has loaded, so in the case that the control is added to the map after the style resource has already loaded it won't trigger. Therefore within control `onAdd` we should check if the map style resource is already loaded and if so immediately trigger the `initialStyleUpdate`. --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 942ad48..b731f46 100644 --- a/index.js +++ b/index.js @@ -156,7 +156,11 @@ function browserLanguage(supportedLanguages) { MapboxLanguage.prototype.onAdd = function (map) { this._map = map; - this._map.on('style.load', this._initialStyleUpdate); + if (this._map.style && this._map.style._loaded) { + this._initialStyleUpdate(); + } else { + this._map.on('style.load', this._initialStyleUpdate); + } this._container = document.createElement('div'); return this._container; };