Skip to content

Commit

Permalink
Hybrid terrain example (#4971)
Browse files Browse the repository at this point in the history
  • Loading branch information
birkskyum authored Nov 3, 2024
1 parent 927dd71 commit 84efc30
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
Binary file added docs/assets/examples/hybrid-terrain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions test/examples/hybrid-terrain.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<!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='../../dist/maplibre-gl.css' />
<script src='../../dist/maplibre-gl-dev.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.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 = {}

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>

0 comments on commit 84efc30

Please sign in to comment.