UNPKG

earthjs

Version:

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

44 lines (43 loc) 2.15 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> </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}) .register(earthjs.plugins.world3dJson('../d/world.geometry.json', '../d/country_nm_to_id.json')) .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.world3dThreejs(null,'../globe/blue.jpg', 0.95)) .register(earthjs.plugins.choroplethCsv('../data/world_population_2017-10-12.csv')); g._.options.choropleth = true; g.world3dThreejs.style({land: '#883322'}); g.ready(function(){ const arr = '--,CN,IN,US'.split(','); // remove non country, china, india, US const {data, geometries} = g.world3dJson.allData(); g.choroplethCsv.filter(x=>arr.indexOf(x.cid)===-1); g.choroplethCsv.colorize('2016', 'schemeOrRd'); g.choroplethCsv.mergeData(geometries, ['properties.cid:cid', 'properties.color:color']); g.choroplethCsv.mergeData(geometries, ['properties.cid:cid', 'properties.value:2016']); g.world3dThreejs.data(data); g.create(); const o = g.oceanThreejs.sphere(); const t = g.worldThreejs.sphere(); o.material.transparent = true; t.scale.set(1.02,1.02,1.02); }); </script> </body> </html>