1
- import { CommonModule } from '@angular/common' ;
2
- import { AfterViewInit , Component , ElementRef , Input , OnDestroy , ViewChild } from '@angular/core' ;
3
- import { COBEOptionsPart , GlobeOptions } from './ngx-globe.types' ;
4
- import createGlobe from 'cobe' ;
5
- import Phenomenon from 'phenomenon' ;
1
+ import { CommonModule } from "@angular/common" ;
2
+ import {
3
+ AfterViewInit ,
4
+ Component ,
5
+ ElementRef ,
6
+ Input ,
7
+ OnDestroy ,
8
+ ViewChild ,
9
+ } from "@angular/core" ;
10
+ import createGlobe from "cobe" ;
11
+ import Phenomenon from "phenomenon" ;
12
+ import { COBEOptionsPart , GlobeOptions } from "./ngx-globe.types" ;
6
13
7
14
@Component ( {
8
- selector : ' om-globe' ,
15
+ selector : " om-globe" ,
9
16
standalone : true ,
10
17
imports : [ CommonModule ] ,
11
18
templateUrl : "./ngx-globe.component.html" ,
12
19
styleUrl : "./ngx-globe.component.scss" ,
13
20
} )
14
21
export class NgxGlobeComponent implements AfterViewInit , OnDestroy {
15
- @ViewChild ( ' globeCanvas' )
22
+ @ViewChild ( " globeCanvas" )
16
23
globeCanvas ! : ElementRef < HTMLCanvasElement > ;
17
24
18
25
@Input ( "styleClass" )
@@ -36,7 +43,7 @@ export class NgxGlobeComponent implements AfterViewInit, OnDestroy {
36
43
this . globeSize = size ;
37
44
this . cobeOptions . width = this . globeSize ;
38
45
this . cobeOptions . height = this . globeSize ;
39
- this . style [ "--globe-size" ] = size + 'px' ;
46
+ this . style [ "--globe-size" ] = size + "px" ;
40
47
41
48
if ( this . globeInitialized ) {
42
49
this . initGlobe ( ) ;
@@ -90,6 +97,12 @@ export class NgxGlobeComponent implements AfterViewInit, OnDestroy {
90
97
91
98
ngOnDestroy ( ) : void {
92
99
this . globe ?. destroy ( ) ;
100
+ window . removeEventListener ( "resize" , ( ) => this . setCanvasSize ( ) ) ;
101
+ }
102
+
103
+ setCanvasSize ( ) : void {
104
+ this . globeCanvas . nativeElement . width = this . globeSize ;
105
+ this . globeCanvas . nativeElement . height = this . globeSize ;
93
106
}
94
107
95
108
initGlobe ( ) : void {
@@ -101,49 +114,58 @@ export class NgxGlobeComponent implements AfterViewInit, OnDestroy {
101
114
phi += this . rotationSpeed ;
102
115
}
103
116
104
- state . phi = phi + this . globeRotation
117
+ state . phi = phi + this . globeRotation ;
105
118
} ,
106
- }
119
+ } ;
107
120
108
121
this . globe = createGlobe ( this . globeCanvas . nativeElement , cobeOptions ) ;
109
122
110
123
this . globeInitialized = true ;
111
124
125
+ window . addEventListener ( "resize" , ( ) => this . setCanvasSize ( ) ) ;
126
+
112
127
this . globeCanvas . nativeElement . width = this . globeSize ;
113
128
this . globeCanvas . nativeElement . height = this . globeSize ;
114
129
}
115
130
116
131
updatePointerInteraction ( value : any ) : void {
117
132
this . pointerInteracting = value ;
118
133
this . globeCanvas . nativeElement . style . cursor = value ? "grabbing" : "grab" ;
119
- } ;
134
+ }
120
135
121
136
updateMovement ( clientX : any ) : void {
122
137
if ( this . pointerInteracting !== null ) {
123
138
const delta = clientX - this . pointerInteracting ;
124
139
this . pointerInteractionMovement = delta ;
125
140
this . globeRotation = delta / 200 ;
126
141
}
127
- } ;
142
+ }
128
143
129
144
setGlobeOptions ( options : GlobeOptions ) : void {
130
- this . cobeOptions . width = options . width ?? this . cobeOptions . width
131
- this . cobeOptions . height = options . height ?? this . cobeOptions . height
132
- this . cobeOptions . phi = options . phi ?? this . cobeOptions . phi
133
- this . cobeOptions . theta = options . theta ?? this . cobeOptions . theta
134
- this . cobeOptions . mapSamples = options . mapSamples ?? this . cobeOptions . mapSamples
135
- this . cobeOptions . mapBrightness = options . mapBrightness ?? this . cobeOptions . mapBrightness
136
- this . cobeOptions . mapBaseBrightness = options . mapBaseBrightness ?? this . cobeOptions . mapBaseBrightness
137
- this . cobeOptions . baseColor = options . baseColor ?? this . cobeOptions . baseColor
138
- this . cobeOptions . markerColor = options . markerColor ?? this . cobeOptions . markerColor
139
- this . cobeOptions . glowColor = options . glowColor ?? this . cobeOptions . glowColor
140
- this . cobeOptions . markers = options . markers ?? this . cobeOptions . markers
141
- this . cobeOptions . diffuse = options . diffuse ?? this . cobeOptions . diffuse
142
- this . cobeOptions . devicePixelRatio = options . devicePixelRatio ?? this . cobeOptions . devicePixelRatio
143
- this . cobeOptions . dark = options . dark ?? this . cobeOptions . dark
144
- this . cobeOptions . opacity = options . opacity ?? this . cobeOptions . opacity
145
- this . cobeOptions . offset = options . offset ?? this . cobeOptions . offset
146
- this . cobeOptions . scale = options . scale ?? this . cobeOptions . scale
147
- this . cobeOptions . context = options . context ?? this . cobeOptions . context
145
+ this . cobeOptions . width = options . width ?? this . cobeOptions . width ;
146
+ this . cobeOptions . height = options . height ?? this . cobeOptions . height ;
147
+ this . cobeOptions . phi = options . phi ?? this . cobeOptions . phi ;
148
+ this . cobeOptions . theta = options . theta ?? this . cobeOptions . theta ;
149
+ this . cobeOptions . mapSamples =
150
+ options . mapSamples ?? this . cobeOptions . mapSamples ;
151
+ this . cobeOptions . mapBrightness =
152
+ options . mapBrightness ?? this . cobeOptions . mapBrightness ;
153
+ this . cobeOptions . mapBaseBrightness =
154
+ options . mapBaseBrightness ?? this . cobeOptions . mapBaseBrightness ;
155
+ this . cobeOptions . baseColor =
156
+ options . baseColor ?? this . cobeOptions . baseColor ;
157
+ this . cobeOptions . markerColor =
158
+ options . markerColor ?? this . cobeOptions . markerColor ;
159
+ this . cobeOptions . glowColor =
160
+ options . glowColor ?? this . cobeOptions . glowColor ;
161
+ this . cobeOptions . markers = options . markers ?? this . cobeOptions . markers ;
162
+ this . cobeOptions . diffuse = options . diffuse ?? this . cobeOptions . diffuse ;
163
+ this . cobeOptions . devicePixelRatio =
164
+ options . devicePixelRatio ?? this . cobeOptions . devicePixelRatio ;
165
+ this . cobeOptions . dark = options . dark ?? this . cobeOptions . dark ;
166
+ this . cobeOptions . opacity = options . opacity ?? this . cobeOptions . opacity ;
167
+ this . cobeOptions . offset = options . offset ?? this . cobeOptions . offset ;
168
+ this . cobeOptions . scale = options . scale ?? this . cobeOptions . scale ;
169
+ this . cobeOptions . context = options . context ?? this . cobeOptions . context ;
148
170
}
149
171
}
0 commit comments