@@ -5,6 +5,7 @@ import { useTheme } from "next-themes"
5
5
import Globe from "react-globe.gl"
6
6
import { type GlobeMethods } from "react-globe.gl"
7
7
import * as THREE from "three"
8
+ import { OrbitControls } from "three/examples/jsm/controls/OrbitControls"
8
9
9
10
import Link from "@/components/ui/Link"
10
11
@@ -29,6 +30,14 @@ type CountryFeature = {
29
30
}
30
31
}
31
32
33
+ // Extend OrbitControls type to include _sphericalDelta
34
+ interface ExtendedOrbitControls extends OrbitControls {
35
+ _sphericalDelta ?: {
36
+ theta : number
37
+ phi : number
38
+ }
39
+ }
40
+
32
41
const TenYearGlobe = ( { events } : { events : EventData [ ] } ) => {
33
42
const globeRef = useRef < GlobeMethods > ( )
34
43
const globeContainerRef = useRef < HTMLDivElement > ( null )
@@ -71,10 +80,11 @@ const TenYearGlobe = ({ events }: { events: EventData[] }) => {
71
80
72
81
useEffect ( ( ) => {
73
82
if ( globeRef . current ) {
74
- globeRef . current . controls ( ) . autoRotate = true
75
- globeRef . current . controls ( ) . enablePan = false
76
- globeRef . current . controls ( ) . enableZoom = false
77
- globeRef . current . controls ( ) . autoRotateSpeed = 2.0
83
+ const controls = globeRef . current . controls ( ) as ExtendedOrbitControls
84
+ controls . autoRotate = true
85
+ controls . enablePan = false
86
+ controls . enableZoom = false
87
+ controls . autoRotateSpeed = 2.0
78
88
globeRef . current . pointOfView ( { lat : 0 , lng : 0 , altitude : 1.8 } )
79
89
80
90
const ambientLight = new THREE . AmbientLight ( 0xffffff , 1 )
@@ -165,10 +175,10 @@ const TenYearGlobe = ({ events }: { events: EventData[] }) => {
165
175
setTooltipPos ( coords )
166
176
}
167
177
// Stop rotation immediately
168
- const controls = globeRef . current . controls ( )
178
+ const controls = globeRef . current . controls ( ) as ExtendedOrbitControls
169
179
controls . autoRotate = false
170
180
if ( "autoRotateSpeed" in controls ) controls . autoRotateSpeed = 0
171
- if ( "_sphericalDelta" in controls && controls . _sphericalDelta ) {
181
+ if ( controls . _sphericalDelta ) {
172
182
controls . _sphericalDelta . theta = 0
173
183
controls . _sphericalDelta . phi = 0
174
184
}
@@ -181,18 +191,19 @@ const TenYearGlobe = ({ events }: { events: EventData[] }) => {
181
191
}
182
192
} , 100 )
183
193
if ( globeRef . current ) {
184
- const controls = globeRef . current . controls ( )
194
+ const controls =
195
+ globeRef . current . controls ( ) as ExtendedOrbitControls
185
196
controls . autoRotate = true
186
197
if ( "autoRotateSpeed" in controls ) controls . autoRotateSpeed = 2.0
187
198
}
188
199
}
189
200
} }
190
201
onPointClick = { ( ) => {
191
202
if ( globeRef . current ) {
192
- const controls = globeRef . current . controls ( )
203
+ const controls = globeRef . current . controls ( ) as ExtendedOrbitControls
193
204
controls . autoRotate = false
194
205
if ( "autoRotateSpeed" in controls ) controls . autoRotateSpeed = 0
195
- if ( "_sphericalDelta" in controls && controls . _sphericalDelta ) {
206
+ if ( controls . _sphericalDelta ) {
196
207
controls . _sphericalDelta . theta = 0
197
208
controls . _sphericalDelta . phi = 0
198
209
}
0 commit comments