UNPKG

globe.gl

Version:

UI component for Globe Data Visualization using ThreeJS/WebGL

39 lines (32 loc) 1.49 kB
<head> <style> body { margin: 0; } </style> <script src="//cdn.jsdelivr.net/npm/globe.gl"></script> <!--<script src="../../dist/globe.gl.js"></script>--> </head> <body> <div id="globeViz"></div> <script type="module"> import { csvParse } from 'https://esm.sh/d3-dsv'; import { scaleSequentialSqrt } from 'https://esm.sh/d3-scale'; import { interpolateYlOrRd } from 'https://esm.sh/d3-scale-chromatic'; const weightColor = scaleSequentialSqrt(interpolateYlOrRd) .domain([0, 1e7]); const world = new Globe(document.getElementById('globeViz')) .globeImageUrl('//cdn.jsdelivr.net/npm/three-globe/example/img/earth-night.jpg') .bumpImageUrl('//cdn.jsdelivr.net/npm/three-globe/example/img/earth-topology.png') .backgroundImageUrl('//cdn.jsdelivr.net/npm/three-globe/example/img/night-sky.png') .hexBinPointWeight('pop') .hexAltitude(d => d.sumWeight * 6e-8) .hexBinResolution(4) .hexTopColor(d => weightColor(d.sumWeight)) .hexSideColor(d => weightColor(d.sumWeight)) .hexBinMerge(true) .enablePointerInteraction(false); // performance improvement fetch('../datasets/world_population.csv').then(res => res.text()) .then(csv => csvParse(csv, ({ lat, lng, pop }) => ({ lat: +lat, lng: +lng, pop: +pop }))) .then(data => world.hexBinPointsData(data)); // Add auto-rotation world.controls().autoRotate = true; world.controls().autoRotateSpeed = 0.6; </script> </body>