-
Notifications
You must be signed in to change notification settings - Fork 327
/
index.html
56 lines (47 loc) · 2.01 KB
/
index.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
<head>
<style> body { margin: 0; } </style>
<script src="//unpkg.com/globe.gl"></script>
<!-- <script src="../../dist/globe.gl.js"></script>-->
</head>
<body>
<div id="globeViz"></div>
<script>
const ARC_REL_LEN = 0.4; // relative to whole arc
const FLIGHT_TIME = 1000;
const NUM_RINGS = 3;
const RINGS_MAX_R = 5; // deg
const RING_PROPAGATION_SPEED = 5; // deg/sec
const globe = new Globe(document.getElementById('globeViz'))
.globeImageUrl('//unpkg.com/three-globe/example/img/earth-night.jpg')
.arcColor(() => 'darkOrange')
.onGlobeClick(emitArc)
.arcDashLength(ARC_REL_LEN)
.arcDashGap(2)
.arcDashInitialGap(1)
.arcDashAnimateTime(FLIGHT_TIME)
.arcsTransitionDuration(0)
.ringColor(() => t => `rgba(255,100,50,${1-t})`)
.ringMaxRadius(RINGS_MAX_R)
.ringPropagationSpeed(RING_PROPAGATION_SPEED)
.ringRepeatPeriod(FLIGHT_TIME * ARC_REL_LEN / NUM_RINGS);
let prevCoords = { lat: 0, lng: 0 };
function emitArc({ lat: endLat, lng: endLng }) {
const { lat: startLat, lng: startLng } = prevCoords;
setTimeout(() => { prevCoords = { lat: endLat, lng: endLng }}, FLIGHT_TIME);
// add and remove arc after 1 cycle
const arc = { startLat, startLng, endLat, endLng };
globe.arcsData([...globe.arcsData(), arc]);
setTimeout(() => globe.arcsData(globe.arcsData().filter(d => d !== arc)), FLIGHT_TIME * 2);
// add and remove start rings
const srcRing = { lat: startLat, lng: startLng };
globe.ringsData([...globe.ringsData(), srcRing]);
setTimeout(() => globe.ringsData(globe.ringsData().filter(r => r !== srcRing)), FLIGHT_TIME * ARC_REL_LEN);
// add and remove target rings
setTimeout(() => {
const targetRing = { lat: endLat, lng: endLng };
globe.ringsData([...globe.ringsData(), targetRing]);
setTimeout(() => globe.ringsData(globe.ringsData().filter(r => r !== targetRing)), FLIGHT_TIME * ARC_REL_LEN);
}, FLIGHT_TIME);
}
</script>
</body>