-
Notifications
You must be signed in to change notification settings - Fork 154
/
index.html
65 lines (52 loc) · 2.03 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
57
58
59
60
61
62
63
64
65
<head>
<style> body { margin: 0; } </style>
<script src="//unpkg.com/react/umd/react.production.min.js"></script>
<script src="//unpkg.com/react-dom/umd/react-dom.production.min.js"></script>
<script src="//unpkg.com/@babel/standalone"></script>
<script src="//unpkg.com/d3"></script>
<script src="//unpkg.com/react-globe.gl"></script>
<!--<script src="../../dist/react-globe.gl.js"></script>-->
</head>
<body>
<div id="globeViz"></div>
<script type="text/jsx">
const { useState, useEffect, useMemo } = React;
const World = () => {
const [countries, setCountries] = useState({ features: []});
const [hoverD, setHoverD] = useState();
useEffect(() => {
// load data
fetch('../datasets/ne_110m_admin_0_countries.geojson').then(res => res.json()).then(setCountries);
}, []);
const colorScale = d3.scaleSequentialSqrt(d3.interpolateYlOrRd);
// GDP per capita (avoiding countries with small pop)
const getVal = feat => feat.properties.GDP_MD_EST / Math.max(1e5, feat.properties.POP_EST);
const maxVal = useMemo(
() => Math.max(...countries.features.map(getVal)),
[countries]
);
colorScale.domain([0, maxVal]);
return <Globe
globeImageUrl="//unpkg.com/three-globe/example/img/earth-night.jpg"
backgroundImageUrl="//unpkg.com/three-globe/example/img/night-sky.png"
lineHoverPrecision={0}
polygonsData={countries.features.filter(d => d.properties.ISO_A2 !== 'AQ')}
polygonAltitude={d => d === hoverD ? 0.12 : 0.06}
polygonCapColor={d => d === hoverD ? 'steelblue' : colorScale(getVal(d))}
polygonSideColor={() => 'rgba(0, 100, 0, 0.15)'}
polygonStrokeColor={() => '#111'}
polygonLabel={({ properties: d }) => `
<b>${d.ADMIN} (${d.ISO_A2}):</b> <br />
GDP: <i>${d.GDP_MD_EST}</i> M$<br/>
Population: <i>${d.POP_EST}</i>
`}
onPolygonHover={setHoverD}
polygonsTransitionDuration={300}
/>;
};
ReactDOM.render(
<World />,
document.getElementById('globeViz')
);
</script>
</body>