UNPKG

earthjs

Version:

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

42 lines (41 loc) 2.01 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/2010_alcohol_consumption_by_country.csv')); g._.options.choropleth = true; g.world3dThreejs.style({land: '#883322'}); g.ready(function(){ const {data, geometries} = g.world3dJson.allData(); g.choroplethCsv.colorize('alcohol', 'schemeReds'); g.choroplethCsv.mergeData(geometries, ['properties.cid:cid', 'properties.color:color']); g.choroplethCsv.mergeData(geometries, ['properties.cid:cid', 'properties.value:alcohol']); 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>