MapSnippets logoMapSnippets logo

Set Map Language with MapTiler SDK

MapTiler SDK

Change map label language at runtime with the SDK-exclusive setLanguage() method: no style reload needed.

progress_activityLoading map...
maptilersdk.config.apiKey = 'YOUR_MAPTILER_KEY';
const map = new maptilersdk.Map({
  container: 'map',
  style: maptilersdk.MapStyle.STREETS,
  center: [14.42, 50.08],
  zoom: 5,
  language: 'en'
});
window.setLang = function(lang) {
  map.setLanguage(lang);
};

How it works

The MapTiler SDK provides a built-in language option in the Map constructor and a setLanguage() method for runtime changes. This is simpler than the raw MapLibre approach because you do not need to reconstruct the style URL yourself.

Pass a language code like 'en', 'de', or 'ja' to set labels globally. The special value 'local' displays each region’s native language. The SDK handles the style URL construction and reload internally.

Unlike calling setStyle() directly, setLanguage() is a dedicated method that the SDK optimizes for language switching. It updates label layers without requiring you to manually manage custom sources and layers.

Key APIs

API Description Docs
language option Set initial label language in constructor docs.maptiler.com/sdk-js/api/
map.setLanguage() Change label language at runtime docs.maptiler.com/sdk-js/api/
maptilersdk.MapStyle Built-in style constants docs.maptiler.com/sdk-js/api/

FAQ

Which languages are supported?

MapTiler supports 50+ languages including major world languages (en, de, fr, es, zh, ja, ar, ko) and regional languages (cs, uk, vi). Use 'local' to display each region’s native labels.

Does setLanguage() preserve my custom layers?

The SDK’s setLanguage() is designed to update labels without a full style reload. However, behavior may depend on the SDK version: always test with your custom layers to confirm they persist.

Can I set the language per layer?

No. The language option and setLanguage() apply to all label layers in the style. For per-layer control, modify the style specification directly.

Common mistakes

  • Using setStyle() instead of setLanguage(): the SDK’s dedicated method is simpler and avoids unnecessary style reloads
  • Forgetting the language constructor option and relying only on runtime switching: set a sensible default in the constructor
  • Passing a full locale string like 'en-US' instead of a two-letter code like 'en'
auto_awesome

Build maps using MapTiler SDK with AI

Generate code like this set map language with maptiler sdk example using the MapTiler SDK skill in your IDE.