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 createGlobe from "cobe" ;
11
4
import Phenomenon from "phenomenon" ;
12
- import { COBEOptionsPart , GlobeOptions } from "./ngx-globe.types" ;
5
+ import { COBEOptionsPart , GlobeOptions } from "./ngx-globe.types" ;
13
6
14
7
@Component ( {
15
8
selector : "om-globe" ,
@@ -74,16 +67,16 @@ export class NgxGlobeComponent implements AfterViewInit, OnDestroy {
74
67
glowColor : [ 1 , 1 , 1 ] ,
75
68
offset : [ 0 , 0 ] ,
76
69
markers : [
77
- { location : [ 14.5995 , 120.9842 ] , size : 0.03 } ,
78
- { location : [ 19.076 , 72.8777 ] , size : 0.1 } ,
79
- { location : [ 23.8103 , 90.4125 ] , size : 0.05 } ,
80
- { location : [ 30.0444 , 31.2357 ] , size : 0.07 } ,
81
- { location : [ 39.9042 , 116.4074 ] , size : 0.08 } ,
82
- { location : [ - 23.5505 , - 46.6333 ] , size : 0.1 } ,
83
- { location : [ 19.4326 , - 99.1332 ] , size : 0.1 } ,
84
- { location : [ 40.7128 , - 74.006 ] , size : 0.1 } ,
85
- { location : [ 34.6937 , 135.5022 ] , size : 0.05 } ,
86
- { location : [ 41.0082 , 28.9784 ] , size : 0.06 } ,
70
+ { location : [ 14.5995 , 120.9842 ] , size : 0.03 } ,
71
+ { location : [ 19.076 , 72.8777 ] , size : 0.1 } ,
72
+ { location : [ 23.8103 , 90.4125 ] , size : 0.05 } ,
73
+ { location : [ 30.0444 , 31.2357 ] , size : 0.07 } ,
74
+ { location : [ 39.9042 , 116.4074 ] , size : 0.08 } ,
75
+ { location : [ - 23.5505 , - 46.6333 ] , size : 0.1 } ,
76
+ { location : [ 19.4326 , - 99.1332 ] , size : 0.1 } ,
77
+ { location : [ 40.7128 , - 74.006 ] , size : 0.1 } ,
78
+ { location : [ 34.6937 , 135.5022 ] , size : 0.05 } ,
79
+ { location : [ 41.0082 , 28.9784 ] , size : 0.06 } ,
87
80
] ,
88
81
} ;
89
82
@@ -94,13 +87,20 @@ export class NgxGlobeComponent implements AfterViewInit, OnDestroy {
94
87
private intersectionObserver ?: IntersectionObserver ;
95
88
private isAnimating = false ;
96
89
90
+ constructor (
91
+ @Inject ( PLATFORM_ID ) private platformId : object
92
+ ) {
93
+ }
94
+
97
95
ngAfterViewInit ( ) : void {
98
96
this . initGlobe ( ) ;
99
97
100
- this . intersectionObserver = new IntersectionObserver ( ( [ entry ] ) => {
101
- this . renderContents ( entry . isIntersecting ) ;
102
- } ) ;
103
- this . intersectionObserver . observe ( this . globeCanvas . nativeElement ) ;
98
+ if ( isPlatformBrowser ( this . platformId ) ) {
99
+ this . intersectionObserver = new IntersectionObserver ( ( [ entry ] ) => {
100
+ this . renderContents ( entry . isIntersecting ) ;
101
+ } ) ;
102
+ this . intersectionObserver . observe ( this . globeCanvas . nativeElement ) ;
103
+ }
104
104
}
105
105
106
106
ngOnDestroy ( ) : void {
0 commit comments