earthjs
Version:
D3 Earth JS using SVG, Canvas & THREE js, build with some plugins.
44 lines (42 loc) • 1.96 kB
HTML
<html>
<head>
<link type="text/css" rel="stylesheet" href="../css/earthjs.css">
<script type='text/javascript' src="../js/d3.min.js"></script>
<script type='text/javascript' src='../js/three.min.js'></script>
<script type='text/javascript' src="../js/topojson.min.js"></script>
<script type='text/javascript' src="../js/d3-scale-chromatic.v1.min.js"></script>
<script type='text/javascript' src='../js/earthjs.js'></script>
</head>
<body>
<svg id="earth-js"></svg>
<canvas id="three-js"></canvas>
<script>
const {offsetWidth, offsetHeight} = d3.select('body').node();
const g = earthjs({width: offsetWidth, height: offsetHeight, padding:5, transparent: true})
.register(earthjs.plugins.threejsPlugin())
.register(earthjs.plugins.inertiaPlugin())
.register(earthjs.plugins.autorotatePlugin())
.register(earthjs.plugins.graticuleThreejs())
.register(earthjs.plugins.canvasThreejs('../d/world-110m.json'))
.register(earthjs.plugins.dotsThreejs('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojson'));
g.dotsThreejs.ready = function(err, json) {
const arr = json.features;
const range = d3.range.apply(d3, [1,8]);
const minMax = d3.extent(arr.map(d => d.properties.mag));
const vScale = d3.scaleLinear().domain(minMax).range([0.5, 2]);
const scale = d3.scaleLinear().domain(minMax).rangeRound([1,8]);
const color = d3.scaleThreshold().domain(range).range(d3.schemeReds[9]);
arr.forEach(d => {
const {mag} = d.properties;
d.geometry.value = mag;
d.geometry.radius = vScale(mag);
d.geometry.color = color(scale(mag));
});
g.dotsThreejs.data(json);
};
g.ready(function(){
g.create();
})
</script>
</body>
</html>