Skip to content

Commit 515d41e

Browse files
author
Markus Block
committed
Fixed a bug with vertical resizing breaking the existing globe size
1 parent e7670b7 commit 515d41e

File tree

2 files changed

+53
-31
lines changed

2 files changed

+53
-31
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@omnedia/ngx-globe",
33
"description": "A simple component library to create a container with an animated and interactive globe.",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"peerDependencies": {
66
"@angular/common": "^18.2.0",
77
"@angular/core": "^18.2.0",

src/lib/ngx-globe.component.ts

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
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";
613

714
@Component({
8-
selector: 'om-globe',
15+
selector: "om-globe",
916
standalone: true,
1017
imports: [CommonModule],
1118
templateUrl: "./ngx-globe.component.html",
1219
styleUrl: "./ngx-globe.component.scss",
1320
})
1421
export class NgxGlobeComponent implements AfterViewInit, OnDestroy {
15-
@ViewChild('globeCanvas')
22+
@ViewChild("globeCanvas")
1623
globeCanvas!: ElementRef<HTMLCanvasElement>;
1724

1825
@Input("styleClass")
@@ -36,7 +43,7 @@ export class NgxGlobeComponent implements AfterViewInit, OnDestroy {
3643
this.globeSize = size;
3744
this.cobeOptions.width = this.globeSize;
3845
this.cobeOptions.height = this.globeSize;
39-
this.style["--globe-size"] = size + 'px';
46+
this.style["--globe-size"] = size + "px";
4047

4148
if (this.globeInitialized) {
4249
this.initGlobe();
@@ -90,6 +97,12 @@ export class NgxGlobeComponent implements AfterViewInit, OnDestroy {
9097

9198
ngOnDestroy(): void {
9299
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;
93106
}
94107

95108
initGlobe(): void {
@@ -101,49 +114,58 @@ export class NgxGlobeComponent implements AfterViewInit, OnDestroy {
101114
phi += this.rotationSpeed;
102115
}
103116

104-
state.phi = phi + this.globeRotation
117+
state.phi = phi + this.globeRotation;
105118
},
106-
}
119+
};
107120

108121
this.globe = createGlobe(this.globeCanvas.nativeElement, cobeOptions);
109122

110123
this.globeInitialized = true;
111124

125+
window.addEventListener("resize", () => this.setCanvasSize());
126+
112127
this.globeCanvas.nativeElement.width = this.globeSize;
113128
this.globeCanvas.nativeElement.height = this.globeSize;
114129
}
115130

116131
updatePointerInteraction(value: any): void {
117132
this.pointerInteracting = value;
118133
this.globeCanvas.nativeElement.style.cursor = value ? "grabbing" : "grab";
119-
};
134+
}
120135

121136
updateMovement(clientX: any): void {
122137
if (this.pointerInteracting !== null) {
123138
const delta = clientX - this.pointerInteracting;
124139
this.pointerInteractionMovement = delta;
125140
this.globeRotation = delta / 200;
126141
}
127-
};
142+
}
128143

129144
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;
148170
}
149171
}

0 commit comments

Comments
 (0)