Display and style rich text labels

Use the format expression to display country labels in both English and in the local language.

NPM module setup


npm install --save @maptiler/sdk
import { Map, MapStyle, config } from '@maptiler/sdk';
import '@maptiler/sdk/dist/maptiler-sdk.css';

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';

const map = new Map({
    container: 'map', // container id
    style: MapStyle.BASE,
    center: [9.49, 49.01], // starting position [lng, lat]
    zoom: 4 // starting zoom
});

map.on('load', function () {
    map.setLayoutProperty('Country labels', 'text-field', [
        'format',
        ['get', 'name:en'],
        { 'font-scale': 1.2 },
        '\n',
        {},
        ['get', 'name:de'],
        {
            'font-scale': 0.8,
            'text-font': [
                'literal',
                ['DIN Offc Pro Italic', 'Arial Unicode MS Regular']
            ]
        }
    ]);
});
Change the case of labels

Change the case of labels

Examples

Modify label text casing using upcase and downcase expressions.

Icon image URL inside a rich text format label

Icon image URL inside a rich text format label

Examples

Display rich text labels with texts and icons.

How to change the default map labels language

Set map language

Tutorials

This tutorial shows how to change the default map labels language.

Add a stretchable image to the map

Add a stretchable image to the map

Examples

Use stretchable images as background for map text labels.

Was this helpful?