UNPKG

earthjs

Version:

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

51 lines (48 loc) 2.2 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> <div class="input-area"> <input id="frm" type="range" min="1" max="1.5" step="0.01" value="1.02"/><br> </div> <svg id="earth-js" class="ej-center"></svg> <canvas id="three-js" class="ej-center"></canvas> <script> const {offsetWidth, offsetHeight} = d3.select('body').node(); const scale = d3.min([offsetWidth, offsetHeight])/3; const g = earthjs({width: offsetWidth, height: offsetHeight, padding:5, scale}) .register(earthjs.plugins.inertiaPlugin()) .register(earthjs.plugins.threejsPlugin()) .register(earthjs.plugins.autorotatePlugin()) .register(earthjs.plugins.oceanThreejs()) .register(earthjs.plugins.graticuleThreejs()) .register(earthjs.plugins.choroplethCsv('../data/2010_alcohol_consumption_by_country.csv')) .register(earthjs.plugins.canvasThreejs('../d/world-110m.json')) g._.options.showSelectedCountry = true; g._.options.choropleth = true; let t,o; g.ready(function(){ const countries = g.canvasThreejs.allData().countries; 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(); t = g.canvasThreejs.sphere(); t.scale.set(1.02,1.02,1.02); o = g.oceanThreejs.sphere(); o.material.transparent = true; }) d3.select('#frm').on('input', function() { const v = this.value; t.scale.set(v,v,v); }) </script> </body> </html>