Release 0.14.0-alpha #42
@@ -16,7 +16,6 @@ interface GlobeProps {
|
|||||||
export default function Globe({ data, className }: GlobeProps) {
|
export default function Globe({ data, className }: GlobeProps) {
|
||||||
const canvasRef = useRef<HTMLCanvasElement>(null)
|
const canvasRef = useRef<HTMLCanvasElement>(null)
|
||||||
const phiRef = useRef(0)
|
const phiRef = useRef(0)
|
||||||
const widthRef = useRef(0)
|
|
||||||
const pointerInteracting = useRef<number | null>(null)
|
const pointerInteracting = useRef<number | null>(null)
|
||||||
const pointerInteractionMovement = useRef(0)
|
const pointerInteractionMovement = useRef(0)
|
||||||
const { resolvedTheme } = useTheme()
|
const { resolvedTheme } = useTheme()
|
||||||
@@ -39,8 +38,8 @@ export default function Globe({ data, className }: GlobeProps) {
|
|||||||
const r = useMotionValue(0)
|
const r = useMotionValue(0)
|
||||||
const rs = useSpring(r, {
|
const rs = useSpring(r, {
|
||||||
mass: 1,
|
mass: 1,
|
||||||
damping: 50,
|
damping: 60,
|
||||||
stiffness: 80,
|
stiffness: 60,
|
||||||
})
|
})
|
||||||
|
|
||||||
const updatePointerInteraction = (value: number | null) => {
|
const updatePointerInteraction = (value: number | null) => {
|
||||||
@@ -61,20 +60,13 @@ export default function Globe({ data, className }: GlobeProps) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!canvasRef.current) return
|
if (!canvasRef.current) return
|
||||||
|
|
||||||
const onResize = () => {
|
const size = canvasRef.current.offsetWidth
|
||||||
if (canvasRef.current) {
|
const pixelRatio = Math.min(window.devicePixelRatio, 2)
|
||||||
widthRef.current = canvasRef.current.offsetWidth
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener('resize', onResize)
|
const globe = createGlobe(canvasRef.current, {
|
||||||
onResize()
|
width: size * pixelRatio,
|
||||||
|
height: size * pixelRatio,
|
||||||
const config: COBEOptions = {
|
devicePixelRatio: pixelRatio,
|
||||||
width: widthRef.current * 2,
|
|
||||||
height: widthRef.current * 2,
|
|
||||||
onRender: () => {},
|
|
||||||
devicePixelRatio: 2,
|
|
||||||
phi: 0,
|
phi: 0,
|
||||||
theta: 0.3,
|
theta: 0.3,
|
||||||
dark: isDark ? 1 : 0,
|
dark: isDark ? 1 : 0,
|
||||||
@@ -85,19 +77,11 @@ export default function Globe({ data, className }: GlobeProps) {
|
|||||||
markerColor: [253 / 255, 94 / 255, 15 / 255],
|
markerColor: [253 / 255, 94 / 255, 15 / 255],
|
||||||
glowColor: isDark ? [0.15, 0.15, 0.15] : [1, 1, 1],
|
glowColor: isDark ? [0.15, 0.15, 0.15] : [1, 1, 1],
|
||||||
markers,
|
markers,
|
||||||
}
|
|
||||||
|
|
||||||
const globe = createGlobe(canvasRef.current, {
|
|
||||||
...config,
|
|
||||||
width: widthRef.current * 2,
|
|
||||||
height: widthRef.current * 2,
|
|
||||||
onRender: (state) => {
|
onRender: (state) => {
|
||||||
if (!pointerInteracting.current) phiRef.current += 0.002
|
if (!pointerInteracting.current) phiRef.current += 0.002
|
||||||
state.phi = phiRef.current + rs.get()
|
state.phi = phiRef.current + rs.get()
|
||||||
state.width = widthRef.current * 2
|
|
||||||
state.height = widthRef.current * 2
|
|
||||||
},
|
},
|
||||||
})
|
} as COBEOptions)
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (canvasRef.current) canvasRef.current.style.opacity = '1'
|
if (canvasRef.current) canvasRef.current.style.opacity = '1'
|
||||||
@@ -105,7 +89,6 @@ export default function Globe({ data, className }: GlobeProps) {
|
|||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
globe.destroy()
|
globe.destroy()
|
||||||
window.removeEventListener('resize', onResize)
|
|
||||||
}
|
}
|
||||||
}, [rs, markers, isDark])
|
}, [rs, markers, isDark])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user