This repository has been archived by the owner on Apr 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 314
/
mercator.html
100 lines (77 loc) · 3.13 KB
/
mercator.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
<!doctype html>
<head>
<title>Mercator projection</title>
<script src="../dist/threebox.js" type="text/javascript"></script>
<script src="config.js"></script>
<script src='https://api.mapbox.com/mapbox-gl-js/v0.50.0/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v0.50.0/mapbox-gl.css' rel='stylesheet' />
<style>
body, html {
width: 100%;
height: 100%;
margin: 0;
}
#map {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id='map' class='map'></div>
<script>
// this example demonstrates the use of duplicate(), to replicate a sphere many times with minimal performance implications. Also shows the distortion effects of mercator: despite their appearance, all spheres have a radius of 500km, at an altitude of 2000km.
if(!config) console.error("Config not set! Make a copy of 'config_template.js', add in your access token, and save the file as 'config.js'.");
mapboxgl.accessToken = config.accessToken;
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v9',
zoom: 0,
pitch: 45,
bearing: 45
});
map.on('style.load', function() {
map.addLayer({
id: 'custom_layer',
type: 'custom',
onAdd: function(map, mbxContext){
window.tb = new Threebox(
map,
mbxContext,
{defaultLights: true}
);
// generate 100 points around the world, at random locations but the same altitude
var randomPoints = [];
for (var i = 0; i < 100; i++){
var point = [
360 * (Math.random()-0.5),
160 * (Math.random()-0.5),
2000000
]
randomPoints.push(point);
}
// build a template sphere sized in meters, such that it will appear to scale with its local surroundings
sphereTemplate = tb.sphere(
{
radius: 500000,
units: 'meters',
sides: 120,
color: 'purple',
material: 'MeshPhysicalMaterial'
}
)
// for best performance, clone the template sphere for each point in randomPoint
randomPoints.forEach(function(pt){
newSphere = sphereTemplate
.duplicate()
.setCoords(pt);
tb.add(newSphere);
})
},
render: function(gl, matrix){
tb.update();
}
});
});
</script>
</body>