forked from mapbox/mapbox-gl-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
raster.html
134 lines (117 loc) · 3.5 KB
/
raster.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
<!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 { height: 100%; }
#map { height: 100%; }
#container {
position: absolute;
top: 1em;
left: 1em;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="container"></div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.7/dat.gui.min.js"></script>
<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/d3.min.js"></script>
<script src="../dist/mapbox-gl-dev.js"></script>
<script src="../debug/access_token_generated.js"></script>
<script>
/*global d3*/
const presets = {
Satellite: {
tileset: "mapbox.satellite",
rasterColor: "Cubehelix",
rasterColorMix: "luminosity",
rasterColorRange: "[0, 1]"
},
Terrain: {
tileset: "mapbox.terrain-rgb",
rasterColor: "Hypsometric",
rasterColorMix: "decode terrain-rgb",
rasterColorRange: "[0, 8848]",
forcePngraw: true
}
};
function GUIParams () {
this.preset = "Satellite";
this.opacity = 0.5;
Object.assign(this, presets[this.preset]);
}
const guiParams = new GUIParams();
const tilesets = {
"mapbox.terrain-rgb": "mapbox.terrain-rgb",
"mapbox.satellite": "mapbox.satellite"
};
function setStyle (tileset) {
map.setStyle({
version: 8,
sources: {
mapbox: {
type: "raster",
url: "mapbox://mapbox.satellite",
tileSize: 256
},
raster: {
type: "raster",
tiles: [ `https://api.mapbox.com/v4/${tilesets[tileset]}/{z}/{x}/{y}@2x.webp` ],
maxzoom: 14,
tileSize: 256
}
},
layers: [{
"id": "background",
"type": "background",
"paint": {
"background-color": "rgb(4,7,14)"
}
},
{
"type": "raster",
"source": "raster",
"id": "raster",
"paint": {
"raster-opacity": guiParams.opacity
}
}]
});
}
var map = window.map = new mapboxgl.Map({
container: "map",
devtools: true,
style: {version: 8, layers: [], sources: {}},
hash: true,
transformRequest (url, type) {
if (type !== "Tile") return;
const preset = presets[guiParams.preset];
if (preset.forbid2x) url = url.replace('@2x', '');
if (preset.forcePngraw) url = url.replace('.webp', '.pngraw');
return {url};
}
});
map.once("load", function () {
var gui = window.gui = new dat.GUI({autoPlace: false}); // eslint-disable-line
document.getElementById('container').appendChild(gui.domElement);
map.setProjection("globe");
const tileset = gui.add(guiParams, "tileset", Object.keys(tilesets));
const opacity = gui.add(guiParams, "opacity", 0, 1);
function setTileset(range) {
setStyle(guiParams.tileset);
}
tileset.onChange(setTileset).listen();
opacity.onChange(opac => {
map.setPaintProperty("raster", "raster-opacity", opac);
document.getElementById("gradient").style.opacity = opac;
});
setTileset(guiParams.tileset);
});
</script>
</body>
</html>