添加多方向山体阴影图层
使用多方向山体阴影图层增强地形表现;
<!DOCTYPE html>
<html lang="en">
<head>
<title>添加多方向山体阴影图层</title>
<meta property="og:description" content="使用多方向山体阴影图层增强地形表现" />
<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 = new maplibregl.Map({
container: 'map',
style: 'https://api.maptiler.com/maps/streets/style.json?key=get_your_own_OpIi9ZULNHzrESv6T2vL',
center: [-121.66, 44.31],
zoom: 12
});
map.on('load', () => {
// 添加DEM(数字高程模型)数据源
map.addSource('dem', {
'type': 'raster-dem',
'url': 'https://api.maptiler.com/tiles/terrain-rgb-v2/tiles.json?key=get_your_own_OpIi9ZULNHzrESv6T2vL',
'tileSize': 256
});
// 添加以DEM为基础的山体阴影图层
map.addLayer({
'id': 'hillshading',
'source': 'dem',
'type': 'hillshade',
'paint': {
// 指定多方向照明
'hillshade-illumination-direction': 335,
'hillshade-illumination-anchor': 'viewport',
// 使用多方向山体阴影(比单一方向更加细腻)
'hillshade-accent-color': 'hsl(39, 58%, 95%)',
'hillshade-highlight-color': 'hsl(0, 0%, 100%)',
'hillshade-shadow-color': 'hsl(45, 45%, 75%)',
'hillshade-exaggeration': 0.5
}
}, 'waterway-label');
});
</script>
</body>
</html>