-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
174 lines (152 loc) · 5.03 KB
/
index.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
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
import ThreeGlobe from "three-globe";
import { Scene, WebGLRenderer } from "three";
import {
PerspectiveCamera,
AmbientLight,
DirectionalLight,
Color,
Fog,
AxesHelper,
DirectionalLightHelper,
CameraHelper,
PointLight,
SphereGeomentry,
} from "three";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControl.js";
import { createGlowMesh } from "three-globe-mesh";
import countries from "./files/globe-data-min.json";
import travel from "./files/my-flights.json";
import airportHistory from "./files/my-airports.json";
import { inherits } from "util";
var renderer, camera, scene, controls;
let mouseX = 0;
let mouseY = 0;
let windowHalfX = window.innerWidth / 2;
let windowHalfY = window.innerHeight / 2;
var Globe;
inherits();
initGlobe();
onWindowResize();
animate();
function init(){
renderer = new WebGLRenderer({antialias: true});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
scene = new Scene();
scene.add(new AmbientLight(0xbbbbbb, 0.3));
scene.background = new Color(0x04d21);
camera = new PerspectiveCamera();
camera.aspect = window.innerWidth/window.innerHeight;
camera.updateProjectionMatrix();
var dLight = new DirectionalLight(0xffffff, 0.8);
dLight.position.set(-800, 2000, 400);
camera.add(dLight);
var dLight1 = new DirectionalLight(0x7982f6, 1);
dLight1.position.set(-200, 500, 200);
camera.add(dLight1);
var dLight2 = new PointLight(0x8566cc, 0.5);
dLight2.position.set(-200, 500, 200);
camera.add(dLight2);
camera.position.z = 400;
camera.position.x = 0;
camera.position.y = 0;
scene.add(camera);
scene.fog = new Fog(0x545ef3, 400, 2000);
controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dynamicDampingFactor = 0.01;
controls.enablePan = false;
controls.minDistance = 200;
controls.maxDistance = 500;
controls.rotateSpeed = 0.8;
controls.zoomSpeed = 1;
controls.autoRotate = false;
controls.minPolarAngle = Math.PI / 3.5;
controls.maxPolarAngle = Math.PI - Math.PI / 3;
window.addEventListener("resize", onWindowResize, false);
window.addEventListener("mousemove", onMouseMove);
}
function initGlobe() {
Globe = new ThreeGlobe()
.arcsData(travelHistory.flights)
.arcsColor((e) => {
return e.status ? "#9cff00" : "#ff4000";
})
.arcsAltitude((e) =>{
return e.arcAlt;
})
.arcsStroke((e) =>{
return e.status ? 0.5 : 0.3;
})
.arcsDashLength(0.9)
.arcDashGap(4)
.arcDashAnimateTime(1000)
.arcsTransitionDuration(1000)
.arcDashInitialGap((e) => e.order * 1)
.labelsData(airportHistory.airports)
.labelColor(() => "#ffcb21")
.labelDotOrientaiton((e) => {
return e.text === "ALA" ? "top" : "right";
})
.labelDotRadius(0.3)
.labelSize((e) => e.size)
.labelText("City")
.labelResolution(6)
.labelAltitude(0.01)
.pointsData(airportHistory.airports)
.pointColor(() => "#ffffff")
.pointMerge(true)
.pointAltitude(0.07)
.pointRadius(0.05)
.hexPolygonsData(countries.features)
.hexPolygonResolution(3)
.hexPolygonMargin(0.7)
.showAtmosphere(false)
.hexPolygonColor((e) => {
if(
["KGZ", "KOR", "THA", "RUS", "UZB", "IDN", "KAZ", "MYS"].includes(
e.properties.ISO_A3
)
){
return "rgba(255,255,255,1)";
}else return "rgba(255,255,255,0.7)";
});
Globe.rotateY(-Math.PI * (5/9));
Globe.rotateX(-Math.PI * 6);
const globeMaterial = Globe.globeMaterial();
globeMaterial.color = new Color(0x3a228a);
globeMaterial.emissive = new Color (0x220038);
globeMaterial.emissiveIntensity = 0.1;
globeMaterial.shininess = 0.7;
var options = {
backside: true,
color: "#3a228a",
size: 100*0.25,
power: 6,
coefficient: 0.3,
};
var glowMesh = createGlowMesh(new SphereGeomentry(100,75,75), options);
Globe.add(glowMesh);
scene.add(Globe);
}
function onMouseMove(event){
mouseX = event.clientX - windowHalfX;
mouseY = event.clientY - windowHalfY;
console.log("x: "+ mouseX + "y: "+ mouseY);
}
function onWindowResize(){
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
windowHalfX = window.innerWidth / 2;
windowHalfY = window.innerHeight / 2;
renderer.setSize(window.innerWidth, window.innerHeight);
}
function animate(){
camera.position.x += Math.abs(mouseX) <= windowHalfX /2 ? (mouseX /2 -camera.position.x)*0.005 :0;
camera.position.y += (-mouseY/2-camera.position.y)*0.005;
camera.lookAt(scene.position);
controls.update();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}