UNPKG

globe.gl

Version:

UI component for Globe Data Visualization using ThreeJS/WebGL

43 lines (37 loc) 1.39 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> const markerSvg = `<svg viewBox="-4 0 36 36"> <path fill="currentColor" d="M14,0 C21.732,0 28,5.641 28,12.6 C28,23.963 14,36 14,36 C14,36 0,24.064 0,12.6 C0,5.641 6.268,0 14,0 Z"></path> <circle fill="black" cx="14" cy="14" r="7"></circle> </svg>`; // Gen random data const N = 30; const gData = [...Array(N).keys()].map(() => ({ lat: (Math.random() - 0.5) * 180, lng: (Math.random() - 0.5) * 360, size: 7 + Math.random() * 30, color: ['red', 'white', 'blue', 'green'][Math.round(Math.random() * 3)] })); new Globe(document.getElementById('globeViz')) .globeImageUrl('//cdn.jsdelivr.net/npm/three-globe/example/img/earth-dark.jpg') .htmlElementsData(gData) .htmlElement(d => { const el = document.createElement('div'); el.innerHTML = markerSvg; el.style.color = d.color; el.style.width = `${d.size}px`; el.style.transition = 'opacity 250ms'; el.style['pointer-events'] = 'auto'; el.style.cursor = 'pointer'; el.onclick = () => console.info(d); return el; }) .htmlElementVisibilityModifier((el, isVisible) => el.style.opacity = isVisible ? 1 : 0);; </script> </body>