Localize map or change dynamically language.
By default, supported languages option is the supported list by mapbox styles.
npm i @mapbox-controls/language
// set language from browser, use 'mul' as fallback
map.addControl(new LanguageControl());
// set custom language while initialization
const languageControl = new LanguageControl({
language: 'ru',
});
map.addControl(languageControl);
// or change language dynamically
languageControl.setLanguage(event.target.value);
export type ControlOptions = {
supportedLanguages?: string[];
language?: string;
getLanguageKey?: (language: string) => string;
excludedLayerIds?: string[];
};
setLanguage(lang?: string | undefined): void;
- set dynamically map language