Use a fallback image

Use a coalesce expression to display another image when a requested image is not available.

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',
    style: MapStyle.STREETS,
    center: [-77, 38.75],
    zoom: 5
});
map.on('load', function () {
    map.addSource('points', {
        'type': 'geojson',
        'data': {
            'type': 'FeatureCollection',
            'features': [
                {
                    'type': 'Feature',
                    'geometry': {
                        'type': 'Point',
                        'coordinates': [
                            -77.03238901390978,
                            38.913188059745586
                        ]
                    },
                    'properties': {
                        'title': 'Washington DC',
                        'icon': 'monument'
                    }
                },
                {
                    'type': 'Feature',
                    'geometry': {
                        'type': 'Point',
                        'coordinates': [-79.9959, 40.4406]
                    },
                    'properties': {
                        'title': 'Pittsburgh',
                        'icon': 'bridges'
                    }
                },
                {
                    'type': 'Feature',
                    'geometry': {
                        'type': 'Point',
                        'coordinates': [-76.2859, 36.8508]
                    },
                    'properties': {
                        'title': 'Norfolk',
                        'icon': 'harbor'
                    }
                }
            ]
        }
    });
    map.addLayer({
        'id': 'points',
        'type': 'symbol',
        'source': 'points',
        'layout': {
            'icon-image': [
                'coalesce',
                ['image', ['concat', ['get', 'icon'], '-15']],
                ['image', 'zoo']
            ],
            'text-field': ['get', 'title'],
            'text-font': ['Open Sans Semibold', 'Arial Unicode MS Bold'],
            'text-offset': [0, 0.6],
            'text-anchor': 'top'
        }
    });
});
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.

Filter symbols by text input

Filter symbols by text input

Examples

Filter symbols by typing names into a text input.

Use locally generated ideographs

Use locally generated ideographs

Examples

Use the localIdeographFontFamily setting to speed up map load times by using locally available fonts instead of font data fetched from the server.

Variable label placement

Variable label placement

Examples

Dynamically shift label positions to keep them visible.

Was this helpful?