添加山体阴影图层
使用基本的山体阴影图层增强地形可视化;
<!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: [-114.5, 37.87],
zoom: 11
});
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
});
// 添加基本的山体阴影图层
map.addLayer(
{
'id': 'hillshading',
'source': 'dem',
'type': 'hillshade'
// 默认参数:
// 'hillshade-illumination-direction': 335,
// 'hillshade-illumination-anchor': 'viewport'
// 'hillshade-exaggeration': 0.5,
},
'waterway-label' // 确保此图层在水道标签下方
);
});
</script>
</body>
</html>