|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { useEffect, useRef } from 'react'; |
| 4 | +import createGlobe from 'cobe'; |
| 5 | + |
1 | 6 | export const Location = () => {
|
| 7 | + const canvasRef = useRef<HTMLCanvasElement>(null); |
| 8 | + |
| 9 | + useEffect(() => { |
| 10 | + const phi = 0; |
| 11 | + let width = 0; |
| 12 | + |
| 13 | + const onResize = () => { |
| 14 | + if (canvasRef.current && (width = canvasRef.current.offsetWidth)) { |
| 15 | + window.addEventListener('resize', onResize); |
| 16 | + } |
| 17 | + }; |
| 18 | + onResize(); |
| 19 | + |
| 20 | + if (!canvasRef.current) return; |
| 21 | + |
| 22 | + const globe = createGlobe(canvasRef.current, { |
| 23 | + devicePixelRatio: 2, |
| 24 | + width: width * 2, |
| 25 | + height: width * 2 * 0.4, |
| 26 | + phi: -0.1, |
| 27 | + theta: -0.13, |
| 28 | + dark: 1, |
| 29 | + diffuse: 3, |
| 30 | + mapSamples: 12_000, |
| 31 | + mapBrightness: 2, |
| 32 | + baseColor: [0.8, 0.8, 0.8], |
| 33 | + markerColor: [1, 1, 1], |
| 34 | + glowColor: [0.2, 0.2, 0.2], |
| 35 | + markers: [{ location: [19.4305305, -99.146796], size: 0.1 }], |
| 36 | + scale: 2.5, |
| 37 | + offset: [0, width * 2 * 0.4 * 0.13], |
| 38 | + onRender: (state) => { |
| 39 | + state.phi = phi; |
| 40 | + state.width = width * 2; |
| 41 | + state.height = width * 2 * 0.4; |
| 42 | + }, |
| 43 | + }); |
| 44 | + |
| 45 | + return () => { |
| 46 | + globe.destroy(); |
| 47 | + window.removeEventListener('resize', onResize); |
| 48 | + }; |
| 49 | + }, []); |
| 50 | + |
2 | 51 | return (
|
3 |
| - <div> |
4 |
| - <p>location</p> |
| 52 | + <div className='max-h-[204px] w-full overflow-hidden'> |
| 53 | + <h4 className='pt-8 font-serif text-lg text-grey-text'>CMDX, Mexico</h4> |
| 54 | + |
| 55 | + <div className='relative mx-auto aspect-square h-full w-full'> |
| 56 | + <canvas |
| 57 | + ref={canvasRef} |
| 58 | + style={{ |
| 59 | + width: '100%', |
| 60 | + height: '100%', |
| 61 | + contain: 'layout paint size', |
| 62 | + cursor: 'auto', |
| 63 | + userSelect: 'none', |
| 64 | + }} |
| 65 | + /> |
| 66 | + </div> |
5 | 67 | </div>
|
6 | 68 | );
|
7 | 69 | };
|
0 commit comments