forked from spaceapi-community/hackerspace-globe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
globe.js
52 lines (42 loc) · 1.94 KB
/
globe.js
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
$(function() {
if (!Detector.webgl) {
Detector.addGetWebGLMessage();
return;
}
var openColor = new THREE.Color(0x00ff00);
var closedColor = new THREE.Color(0xff0000);
function colorize(open) {
return open ? openColor : closedColor;
};
var globe = new DAT.Globe($('#globeContainer').get(0), colorize);
TWEEN.start();
new TWEEN.Tween(globe).to({time: 0},500).easing(TWEEN.Easing.Cubic.EaseOut).start();
globe.animate();
// TODO: have a look at these questions.
//
// 1) does the Globe instance support multiple calls of createPoints()? => it seems so
// 2) is it fine that different spaceapi versions are handled asynchronously? => it seems so
$.getJSON('http://spaceapi.net/directory.json', {api: "<0.13"}, function(urls) {
for (var name in urls) {
$.getJSON(urls[name], function(data) {
if ( data.hasOwnProperty("lat") && data.hasOwnProperty("lon") && data.hasOwnProperty("open") ) {
var open = data.open || false;
globe.addData([parseFloat(data.lat), parseFloat(data.lon), 0.1, open], {format: 'legend'});
globe.createPoints();
}
});
}
});
$.getJSON('http://spaceapi.net/directory.json', {api: ">0.12"}, function(urls) {
for (var name in urls) {
$.getJSON(urls[name], function(data) {
if ( data.hasOwnProperty("state") && data.state.hasOwnProperty("open") && data.hasOwnProperty("location")
&& data.location.hasOwnProperty("lon") && data.location.hasOwnProperty("lat") ) {
globe.addData([parseFloat(data.location.lat), parseFloat(data.location.lon), 0.1, data.state.open], {format: 'legend'});
globe.createPoints();
}
});
}
});
// TODO: Figure out the source of the errors in the console.
});