-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathhighlight-links.html
96 lines (80 loc) · 3.63 KB
/
highlight-links.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
<head>
<style> body { margin: 0; } </style>
<script type="importmap">{ "imports": {
"react": "https://esm.sh/react",
"react-dom": "https://esm.sh/react-dom/client"
}}</script>
<!-- <script type="module">import * as React from 'react'; window.React = React;</script>-->
<!-- <script src="../../dist/react-globe.gl.js" defer></script>-->
</head>
<body>
<div id="globeViz"></div>
<script src="//unpkg.com/@babel/standalone"></script>
<script type="text/jsx" data-type="module">
import Globe from 'https://esm.sh/react-globe.gl?external=react';
import React, { useState, useEffect, useRef } from 'react';
import { createRoot } from 'react-dom';
import { csvParseRows } from 'https://esm.sh/d3-dsv';
import indexBy from 'https://esm.sh/index-array-by';
const COUNTRY = 'Portugal';
const MAP_CENTER = { lat: 37.6, lng: -16.6, altitude: 0.4 };
const OPACITY = 0.3;
const airportParse = ([airportId, name, city, country, iata, icao, lat, lng, alt, timezone, dst, tz, type, source]) => ({ airportId, name, city, country, iata, icao, lat, lng, alt, timezone, dst, tz, type, source });
const routeParse = ([airline, airlineId, srcIata, srcAirportId, dstIata, dstAirportId, codeshare, stops, equipment]) => ({ airline, airlineId, srcIata, srcAirportId, dstIata, dstAirportId, codeshare, stops, equipment});
const World = () => {
const globeEl = useRef();
const [airports, setAirports] = useState([]);
const [routes, setRoutes] = useState([]);
const [hoverArc, setHoverArc] = useState();
useEffect(() => {
// load data
Promise.all([
fetch('https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat').then(res => res.text())
.then(d => csvParseRows(d, airportParse)),
fetch('https://raw.githubusercontent.com/jpatokal/openflights/master/data/routes.dat').then(res => res.text())
.then(d => csvParseRows(d, routeParse))
]).then(([airports, routes]) => {
const filteredAirports = airports.filter(d => d.country === COUNTRY);
const byIata = indexBy(filteredAirports, 'iata', false);
const filteredRoutes = routes
.filter(d => byIata.hasOwnProperty(d.srcIata) && byIata.hasOwnProperty(d.dstIata)) // exclude unknown airports
.filter(d => d.stops === '0') // non-stop flights only
.map(d => Object.assign(d, {
srcAirport: byIata[d.srcIata],
dstAirport: byIata[d.dstIata]
}))
.filter(d => d.srcAirport.country === COUNTRY && d.dstAirport.country === COUNTRY); // domestic routes within country
setAirports(filteredAirports);
setRoutes(filteredRoutes);
globeEl.current.pointOfView(MAP_CENTER, 4000);
});
}, []);
return <Globe
ref={globeEl}
globeImageUrl="//unpkg.com/three-globe/example/img/earth-night.jpg"
arcsData={routes}
arcLabel={d => `${d.airline}: ${d.srcIata} → ${d.dstIata}`}
arcStartLat={d => +d.srcAirport.lat}
arcStartLng={d => +d.srcAirport.lng}
arcEndLat={d => +d.dstAirport.lat}
arcEndLng={d => +d.dstAirport.lng}
arcDashLength={0.4}
arcDashGap={0.2}
arcDashAnimateTime={1500}
arcsTransitionDuration={0}
arcColor={d => {
const op = !hoverArc ? OPACITY : d === hoverArc ? 0.9 : OPACITY / 4;
return [`rgba(0, 255, 0, ${op})`, `rgba(255, 0, 0, ${op})`];
}}
onArcHover={setHoverArc}
pointsData={airports}
pointColor={() => 'orange'}
pointAltitude={0}
pointRadius={0.04}
pointsMerge={true}
/>;
};
createRoot(document.getElementById('globeViz'))
.render(<World />);
</script>
</body>