Created
December 31, 2020 02:47
-
-
Save danswick/bebcca95b7378a8f0129b55c0429dfd4 to your computer and use it in GitHub Desktop.
Mbx GL 3D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Add 3D terrain to a map</title> | |
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /> | |
<script src="https://api.mapbox.com/mapbox-gl-js/v2.0.0/mapbox-gl.js"></script> | |
<link href="https://api.mapbox.com/mapbox-gl-js/v2.0.0/mapbox-gl.css" rel="stylesheet" /> | |
<style> | |
body { margin: 0; padding: 0; } | |
#map { position: absolute; top: 0; bottom: 0; width: 100%; } | |
</style> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script> | |
mapboxgl.accessToken = 'pk.eyJ1IjoiZGFuc3dpY2siLCJhIjoiY2sycW9ucW5kMGduMjNjbHJkcHRxcHRjYyJ9.kxWhRuGFr76e8-KZWl37Ng'; | |
var map = new mapboxgl.Map({ | |
container: 'map', | |
zoom: 15.19, | |
center: [-122.149677, 37.779332], | |
pitch: 77, | |
bearing: -39.2, | |
style: 'mapbox://styles/mapbox/satellite-streets-v11', | |
hash: true | |
}); | |
map.on('load', function () { | |
map.addSource('mapbox-dem', { | |
'type': 'raster-dem', | |
'url': 'mapbox://mapbox.mapbox-terrain-dem-v1', | |
'tileSize': 512, | |
'maxzoom': 17 | |
}); | |
// add the DEM source as a terrain layer with exaggerated height | |
map.setTerrain({ 'source': 'mapbox-dem', 'exaggeration': 1.5 }); | |
// add a sky layer that will show when the map is highly pitched | |
map.addLayer({ | |
'id': 'sky', | |
'type': 'sky', | |
'paint': { | |
'sky-type': 'atmosphere', | |
'sky-atmosphere-sun': [0.0, 0.0], | |
'sky-atmosphere-sun-intensity': 15 | |
} | |
}); | |
map.addControl(new mapboxgl.NavigationControl()); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment