Skip to content

Commit

Permalink
Ensure map retains selected language when changing styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Hamley committed Aug 12, 2021
2 parents d7b2a1a + 08e866d commit 56fe78a
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ MapboxLanguage.prototype._initialStyleUpdate = function () {
var style = this._map.getStyle();
var language = this._defaultLanguage || browserLanguage(this.supportedLanguages);

// We only update the style once
this._map.off('styledata', this._initialStyleUpdate);
this._map.setStyle(this.setLanguage(style, language));
};

Expand All @@ -225,13 +223,13 @@ function browserLanguage(supportedLanguages) {

MapboxLanguage.prototype.onAdd = function (map) {
this._map = map;
this._map.on('styledata', this._initialStyleUpdate);
this._map.on('style.load', this._initialStyleUpdate);
this._container = document.createElement('div');
return this._container;
};

MapboxLanguage.prototype.onRemove = function () {
this._map.off('styledata', this._initialStyleUpdate);
this._map.off('style.load', this._initialStyleUpdate);
this._map = undefined;
};

Expand Down

0 comments on commit 56fe78a

Please sign in to comment.