Skip to content

Add a multidirectional hillshade layer

Add a hillshade layer with multiple illumination sources.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Add a multidirectional hillshade layer</title>
    <meta property="og:description" content="Add a hillshade layer with multiple illumination sources." />
    <meta charset='utf-8'>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel='stylesheet' href='https://unpkg.com/maplibre-gl@5.5.0/dist/maplibre-gl.css' />
    <script src='https://unpkg.com/maplibre-gl@5.5.0/dist/maplibre-gl.js'></script>
    <style>
        body { margin: 0; padding: 0; }
        html, body, #map { height: 100%; }
    </style>
</head>
<body>
<div id='map'></div>

<script>
    const map = window.map = new maplibregl.Map({
        container: 'map',
        zoom: 10,
        center: [11.491, 47.274],
        pitch: 0,
        renderWorldCopies: false,
        hash: true,
        style: {
            version: 8,
            sources: {
                hillshadeSource: {
                    type: 'raster-dem',
                    url: 'https://demotiles.maplibre.org/terrain-tiles/tiles.json',
                    tileSize: 256
                }
            },
            layers: [
                {
                    id: 'hillshade',
                    type: 'hillshade',
                    source: 'hillshadeSource',
                    paint: {
                        'hillshade-method': 'multidirectional',
                        'hillshade-highlight-color': ['#FF4000', '#FFFF00', '#40ff00', '#00FF80'],
                        'hillshade-shadow-color': ['#00bfff', '#0000ff', '#bf00ff', '#FF0080'],
                        'hillshade-illumination-direction': [270, 315, 0, 45],
                        'hillshade-illumination-altitude': [30, 30, 30, 30]
                    }
                }
            ]
        },
        maxZoom: 18,
        maxPitch: 85
    });
</script>

</body>
</html>