forked from mapbox/mapbox-gl-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hillshade.html
177 lines (155 loc) · 4.59 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html>
<head>
<title>Mapbox GL JS debug page</title>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel='stylesheet' href='../dist/mapbox-gl.css' />
<style>
body { margin: 0; padding: 0; }
html, body, #map { height: 100%; }
#checkboxes {
position: absolute;
top:0;
left:0;
padding:10px;
}
</style>
</head>
<body>
<style>
#menu {
background: #fff;
position: absolute;
z-index: 1;
top: 10px;
right: 10px;
border-radius: 3px;
width: 140px;
border: 1px solid rgba(0,0,0,0.4);
font-family: 'Open Sans', sans-serif;
}
#menu a {
font-size: 13px;
color: #404040;
display: block;
margin: 0;
padding: 0;
padding: 10px;
text-decoration: none;
border-bottom: 1px solid rgba(0,0,0,0.25);
text-align: center;
}
#menu a:last-child {
border: none;
}
#menu a:hover {
background-color: #f8f8f8;
color: #404040;
}
#menu a.active {
background-color: #3887be;
color: #ffffff;
}
#menu a.active:hover {
background: #3074a4;
}
</style>
<nav id="menu"></nav>
<div id='map'></div>
<div id='checkboxes'>
<label><input id='terrain-checkbox' type='checkbox'> terrain</label><br />
</div>
<script src='../dist/mapbox-gl-dev.js'></script>
<script src='../debug/access_token_generated.js'></script>
<script>
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox:https://styles/mapbox/cjaudgl840gn32rnrepcb9b9g', // the outdoors-v10 style but without Hillshade layers
center: [-119.5591, 37.715],
zoom: 9
});
map.on('load', function () {
map.addSource('mapbox-dem', {
"type": "raster-dem",
"url": "mapbox:https://mapbox.terrain-rgb",
"tileSize": 256,
});
map.addSource('mapbox-terrain', {
"type": "raster-dem",
"url": "mapbox:https://mapbox.terrain-rgb",
"tileSize": 512,
"maxzoom": 14
});
map.addLayer({
"id": "Mapbox data",
"source": "mapbox-dem",
"type": "hillshade"
// insert below waterway-river-canal-shadow;
// where hillshading sits in the Mapbox Outdoors style
}, 'waterway-river-canal-shadow');
map.addSource('terrarium-dem', {
"type": "raster-dem",
"encoding": "terrarium",
"tiles": [
"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png"
],
"tileSize": 128,
"maxzoom": 15
});
map.addLayer({
"id": "Terrarium data",
"source": "terrarium-dem",
"type": "hillshade",
"layout": {
"visibility": "none"
}
// insert below waterway-river-canal-shadow;
// where hillshading sits in the Mapbox Outdoors style
}, 'waterway-river-canal-shadow');
// Add variant of Hillshade that overzooms beyond zoom 7.
// Note: source tiles are 512, so the following only goes up to native zoom 7.
map.addSource('mapbox-dem-z8', {
"type": "raster-dem",
"url": "mapbox:https://mapbox.terrain-rgb",
"tileSize": 256,
"maxzoom": 8
});
map.addLayer({
"id": "Mapbox data to Z8",
"source": "mapbox-dem-z8",
"type": "hillshade",
"layout": {
"visibility": "none"
}
}, 'waterway-river-canal-shadow');
document.getElementById('terrain-checkbox').onclick();
});
var toggleableLayerIds = ['Mapbox data', 'Terrarium data', 'Mapbox data to Z8'];
for (var i = 0; i < toggleableLayerIds.length; i++) {
var id = toggleableLayerIds[i];
var link = document.createElement('a');
link.href = '#';
link.className = (i === 0) ? 'active' : '';
link.textContent = id;
link.onclick = function (e) {
var clickedLayer = this.textContent;
e.preventDefault();
e.stopPropagation();
if (this.className === '') {
var activeLayer = document.getElementsByClassName('active')[0];
activeLayer.className = '';
map.setLayoutProperty(activeLayer.textContent, 'visibility', 'none');
this.className = 'active';
map.setLayoutProperty(clickedLayer, 'visibility', 'visible');
}
};
var layers = document.getElementById('menu');
layers.appendChild(link);
}
document.getElementById('terrain-checkbox').onclick = function() {
map.setTerrain(this.checked ? {"source": 'mapbox-terrain'} : null);
};
</script>
</body>
</html>