1
- import { CommonModule } from "@angular/common" ;
2
- import {
3
- AfterViewInit ,
4
- Component ,
5
- ElementRef ,
6
- Input ,
7
- OnDestroy ,
8
- ViewChild ,
9
- } from "@angular/core" ;
1
+ import { CommonModule , isPlatformBrowser } from "@angular/common" ;
2
+ import { AfterViewInit , Component , ElementRef , Inject , Input , OnDestroy , PLATFORM_ID , ViewChild , } from "@angular/core" ;
10
3
import {
11
4
AmbientLight ,
12
5
Color ,
@@ -19,13 +12,9 @@ import {
19
12
WebGLRenderer ,
20
13
} from "three" ;
21
14
import ThreeGlobe from "three-globe" ;
22
- import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js" ;
23
- import { getData } from "./globe-data" ;
24
- import {
25
- ThreeGlobeConfig ,
26
- ThreeGlobeData ,
27
- ThreeGlobePosition ,
28
- } from "./ngx-three-globe.types" ;
15
+ import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js" ;
16
+ import { getData } from "./globe-data" ;
17
+ import { ThreeGlobeConfig , ThreeGlobeData , ThreeGlobePosition , } from "./ngx-three-globe.types" ;
29
18
30
19
@Component ( {
31
20
selector : "om-three-globe" ,
@@ -47,7 +36,7 @@ export class NgxThreeGlobeComponent implements AfterViewInit, OnDestroy {
47
36
48
37
@ViewChild ( "GlobeCanvas" ) rendererContainer ! : ElementRef ;
49
38
50
- private renderer = new WebGLRenderer ( { alpha : true } ) ;
39
+ private renderer = new WebGLRenderer ( { alpha : true } ) ;
51
40
private scene = new Scene ( ) ;
52
41
private globe = new ThreeGlobe ( ) ;
53
42
private camera = new PerspectiveCamera ( ) ;
@@ -59,7 +48,7 @@ export class NgxThreeGlobeComponent implements AfterViewInit, OnDestroy {
59
48
60
49
@Input ( "globeConfig" )
61
50
set newGlobeConfig ( config : ThreeGlobeConfig ) {
62
- this . globeConfig = { ...this . globeConfig , ...config } ;
51
+ this . globeConfig = { ...this . globeConfig , ...config } ;
63
52
}
64
53
65
54
private globeConfig : ThreeGlobeConfig = {
@@ -426,15 +415,22 @@ export class NgxThreeGlobeComponent implements AfterViewInit, OnDestroy {
426
415
private animationFrameId ?: number ;
427
416
private intersectionObserver ?: IntersectionObserver ;
428
417
418
+ constructor (
419
+ @Inject ( PLATFORM_ID ) private platformId : object
420
+ ) {
421
+ }
422
+
429
423
ngAfterViewInit ( ) : void {
430
424
this . countries = getData ( ) ;
431
425
this . setArcColors ( ) ;
432
426
this . initRenderer ( ) ;
433
427
434
- this . intersectionObserver = new IntersectionObserver ( ( [ entry ] ) => {
435
- this . renderContents ( entry . isIntersecting ) ;
436
- } ) ;
437
- this . intersectionObserver . observe ( this . rendererContainer . nativeElement ) ;
428
+ if ( isPlatformBrowser ( this . platformId ) ) {
429
+ this . intersectionObserver = new IntersectionObserver ( ( [ entry ] ) => {
430
+ this . renderContents ( entry . isIntersecting ) ;
431
+ } ) ;
432
+ this . intersectionObserver . observe ( this . rendererContainer . nativeElement ) ;
433
+ }
438
434
}
439
435
440
436
ngOnDestroy ( ) : void {
@@ -667,7 +663,7 @@ export class NgxThreeGlobeComponent implements AfterViewInit, OnDestroy {
667
663
. ringPropagationSpeed ( 3 )
668
664
. ringRepeatPeriod (
669
665
( ( this . globeConfig . arcTime ?? 0 ) * ( this . globeConfig . arcLength ?? 0 ) ) /
670
- ( this . globeConfig . rings ?? 1 )
666
+ ( this . globeConfig . rings ?? 1 )
671
667
) ;
672
668
}
673
669
@@ -680,10 +676,10 @@ export class NgxThreeGlobeComponent implements AfterViewInit, OnDestroy {
680
676
var result = / ^ # ? ( [ a - f \d ] { 2 } ) ( [ a - f \d ] { 2 } ) ( [ a - f \d ] { 2 } ) $ / i. exec ( hex ) ;
681
677
return result
682
678
? {
683
- r : parseInt ( result [ 1 ] , 16 ) ,
684
- g : parseInt ( result [ 2 ] , 16 ) ,
685
- b : parseInt ( result [ 3 ] , 16 ) ,
686
- }
679
+ r : parseInt ( result [ 1 ] , 16 ) ,
680
+ g : parseInt ( result [ 2 ] , 16 ) ,
681
+ b : parseInt ( result [ 3 ] , 16 ) ,
682
+ }
687
683
: null ;
688
684
}
689
685
0 commit comments