Add hillshading
To improve the visual appeal of a map, this demonstration incorporates raster hillshading. This is achieved by integrating the MapTiler Terrain-DEM raster tileset, as a raster-dem source for the hillshade layer. By doing so, the map gains a realistic representation of terrain elevation and shading.
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',
zoom: 0.3,
center: [0, 20],
style: MapStyle.BASE.LIGHT
});
map.on('load', function () {
map.addSource("terrain", {
"type": "raster-dem",
"url": `https://api.maptiler.com/tiles/terrain-rgb-v2/tiles.json`
});
map.addLayer(
{
'id': 'hillshading',
'source': 'terrain',
'type': 'hillshade'
},
'Residential'
);
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex">
<title>Add hillshading | NPM example | MapTiler SDK JS</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div id="map"></div>
<script type="module" src="./main.js"></script>
</body>
</html>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}