UNPKG

earthjs

Version:

D3 Earth JS using SVG, Canvas & THREE js, build with some plugins.

43 lines (42 loc) 1.93 kB
<!DOCTYPE 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/d3-scale-chromatic.v1.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/earthjs.js'></script> <style media="screen"> body {height: 100vh;margin: 0;} </style> </head> <body> <div class="ej-container"> <svg id="earth-js"></svg> <canvas id="three-js"></canvas> </div> <script> const {offsetWidth, offsetHeight} = d3.select('body').node(); const g = earthjs({width: offsetWidth, height: offsetHeight, padding:5}) .register(earthjs.plugins.inertiaPlugin()) .register(earthjs.plugins.threejsPlugin()) .register(earthjs.plugins.autorotatePlugin()) .register(earthjs.plugins.oceanThreejs()) .register(earthjs.plugins.worldThreejs('../d/world-110m.json')) .register(earthjs.plugins.world3dThreejs2('../d/countries.geo.json','../globe/gold.jpg',0.95)) .register(earthjs.plugins.choroplethCsv('../data/2010_alcohol_consumption_by_country.csv')); g._.options.choropleth = true; g.ready(function(){ const countries = g.world3dThreejs2.data(); g.choroplethCsv .colorize('alcohol', 'schemeReds'); g.choroplethCsv .mergeData(countries, ['properties.cid:cid', 'properties.color:color']); g.choroplethCsv .mergeData(countries, ['properties.cid:cid', 'properties.value:alcohol']); g.create(); var ocean = g.oceanThreejs.sphere(); ocean.scale.set(0.945,0.945,0.945); ocean.material.transparent = true; }); </script> </body> </html>