Skip to content

Commit 2fc56ef

Browse files
committed
feat(components): setup location
1 parent ca89b81 commit 2fc56ef

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed
Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,69 @@
1+
'use client';
2+
3+
import { useEffect, useRef } from 'react';
4+
import createGlobe from 'cobe';
5+
16
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+
251
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>
567
</div>
668
);
769
};

0 commit comments

Comments
 (0)