-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhillshade.html
125 lines (117 loc) · 3.49 KB
/
hillshade.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Display a map</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.1/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<style>
.map-overlay {
font:bold 12px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif;
position: absolute;
width: 25%;
top: 0;
left: 0;
padding: 10px;
}
.map-overlay .map-overlay-inner {
background-color: #fff;
box-shadow:0 1px 2px rgba(0, 0, 0, 0.20);
border-radius: 3px;
padding: 10px;
margin-bottom: 10px;
}
.map-overlay label {
display: block;
margin: 0 0 10px;
}
.map-overlay input {
background-color: transparent;
display: inline-block;
width: 100%;
position: relative;
margin: 0;
cursor: ew-resize;
}
</style>
<div id='map'></div>
<div class='map-overlay top'>
<div class='map-overlay-inner'>
<label>hillshade-exaggeration: <span id='slider-value'>100%</span></label>
<input id='slider' type='range' min='0' max='100' step='0' value='100' />
</div>
</div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoianN0cmF0bSIsImEiOiJPT1hJQmNnIn0.G6gvgXGeQXbQ5cnIj8i7AA';
var tileset = 'mapbox.streets-basic';
var map = new mapboxgl.Map({
container: 'map', // container id
style: {
"version": 8,
"sources": {
"raster-tiles": {
"type": "raster",
"url": "mapbox://" + tileset,
"tileSize": 256
}
},
"layers": [{
"id": "simple-tiles",
"type": "raster",
"source": "raster-tiles",
"minzoom": 0,
"maxzoom": 22
}]
},
center: [-74.50, 40], // starting position
zoom: 12 // starting zoom
});
var slider = document.getElementById('slider');
var sliderValue = document.getElementById('slider-value');
map.on('load', function () {
map.addSource('terrarium-dem', {
"type": "raster-dem",
"encoding": "terrarium",
"tiles": [
"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png"
],
"tileSize": 256
// map.addSource('dem', {
// "type": "raster-dem",
// "url": "mapbox://mapbox.terrain-rgb"
});
map.addLayer({
"id": "Terrarium data",
"source": "terrarium-dem",
"type": "hillshade",
"layout": {
"visibility": "visible"
},
"paint":{
"hillshade-exaggeration": .03,
//"hillshade-shadow-color":"hsla(0, 0%, 0%,0.01)",
// "hillshade-highlight-color":"rgba(0,0,0,0.01)",
// "hillshade-accent-color":"hsla(0, 0%, 0%,0.01)",
}
// insert below waterway-river-canal-shadow;
// where hillshading sits in the Mapbox Outdoors style
});
slider.addEventListener('input', function(e) {
// Adjust the layers opacity. layer here is arbitrary - this could
// be another layer name found in your style or a custom layer
// added on the fly using `addSource`.
map.setPaintProperty('Terrarium data', 'hillshade-exaggeration', parseInt(e.target.value, 10) / 100);
// Value indicator
sliderValue.textContent = e.target.value + '%';
});
});
</script>
</body>
</html>