Display a hybrid satellite map with terrain elevation
Display a hybrid satellite map with terrain elevation.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Display a hybrid satellite map with terrain elevation</title>
<meta property="og:description" content="Display a hybrid satellite map with terrain elevation." />
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel='stylesheet' href='https://unpkg.com/maplibre-gl@5.0.1/dist/maplibre-gl.css' />
<script src='https://unpkg.com/maplibre-gl@5.0.1/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',
zoom: 12,
center: [11.39085, 47.27574],
pitch: 70,
maxPitch: 95
});
map.setStyle('https://api.maptiler.com/maps/hybrid/style.json?key=get_your_own_OpIi9ZULNHzrESv6T2vL', {
transformStyle: (previousStyle, nextStyle) => {
nextStyle.projection = {type: 'globe'};
nextStyle.sources = {
...nextStyle.sources, terrainSource: {
type: 'raster-dem',
url: 'https://api.maptiler.com/tiles/terrain-rgb-v2/tiles.json?key=get_your_own_OpIi9ZULNHzrESv6T2vL',
tileSize: 256
},
hillshadeSource: {
type: 'raster-dem',
url: 'https://api.maptiler.com/tiles/terrain-rgb-v2/tiles.json?key=get_your_own_OpIi9ZULNHzrESv6T2vL',
tileSize: 256
}
}
nextStyle.terrain = {
source: 'terrainSource',
exaggeration: 1
}
nextStyle.sky = {
'atmosphere-blend': [
'interpolate',
['linear'],
['zoom'],
0, 1,
2, 0
],
}
nextStyle.layers.push({
id: 'hills',
type: 'hillshade',
source: 'hillshadeSource',
layout: { visibility: 'visible' },
paint: { 'hillshade-shadow-color': '#473B24' }
})
return nextStyle
}
})
map.addControl(
new maplibregl.NavigationControl({
visualizePitch: true,
showZoom: true,
showCompass: true
})
);
map.addControl(
new maplibregl.GlobeControl()
);
map.addControl(
new maplibregl.TerrainControl({
source: 'terrainSource',
exaggeration: 1
})
);
</script>
</body>
</html>