Leaflet multi-lingual map

This tutorial shows how to change the default map labels language. By default, if nothing is specified, the SDK uses the language defined in the browser. This corresponds to maptilersdk.Language.AUTO. To change the default language of the map, indicate the language in the L.maptiler.maptilerLayer config.

NPM module setup


npm install --save @maptiler/leaflet-maptilersdk leaflet
import { MaptilerLayer, MapStyle, Language } from '@maptiler/leaflet-maptilersdk';
import L from 'leaflet';
import 'leaflet/dist/leaflet.css';

const key = 'YOUR_MAPTILER_API_KEY_HERE';

const map = L.map('map').setView([50, 20], 3);
const mtLayer = new MaptilerLayer({
  apiKey: key,
  style: MapStyle.STREETS, // optional
  language: Language.JAPANESE, //change the default language
}).addTo(map);

document.getElementById('buttons').addEventListener('click', function (event) {
  // Retrieve language based on button id
  mtLayer.setLanguage(Language[event.target.id]);
});

Replace YOUR_MAPTILER_API_KEY_HERE with your own API key. Make sure to secure the key before you publish it.

How to display a custom map on a web with Leaflet

Custom Map

Tutorials

Display custom MapTiler maps on web pages with Leaflet JS.

Leaflet built-in basemap styles

Built-in basemap styles

Examples

Change MapTiler basemap styles easily using Leaflet JS maps.

Was this helpful?