Skip to content

Commit 493ec5c

Browse files
committed
logger, config and selection handling
1 parent c5b9fc7 commit 493ec5c

File tree

14 files changed

+399
-178
lines changed

14 files changed

+399
-178
lines changed

public/config.json

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"propergateInterval": 1000,
3+
"pushHistory": false,
4+
"logLevel": "info",
5+
"satWorker": {
6+
"runOnce": false
7+
},
8+
"satelliteGroups": [
9+
{
10+
"id": "GPSGroup",
11+
"name": "GPS",
12+
"groupType": "intlDes",
13+
"data": [
14+
"90103A",
15+
"93068A",
16+
"96041A",
17+
"97035A",
18+
"99055A",
19+
"00025A",
20+
"00040A",
21+
"00071A",
22+
"01004A",
23+
"03005A",
24+
"03010A",
25+
"03058A",
26+
"04009A",
27+
"04023A",
28+
"04045A",
29+
"05038A",
30+
"06042A",
31+
"06052A",
32+
"07047A",
33+
"07062A",
34+
"08012A",
35+
"09043A",
36+
"10022A",
37+
"11036A",
38+
"12053A",
39+
"13023A",
40+
"14008A",
41+
"14026A",
42+
"14045A",
43+
"14068A",
44+
"15013A"
45+
]
46+
},
47+
{
48+
"id": "IridiumGroup",
49+
"name": "Iridium Debris",
50+
"groupType": "nameRegex",
51+
"data": "IRIDIUM(?!.*DEB)"
52+
},
53+
{
54+
"id": "Iridium33DebrisGroup",
55+
"name": "Iridium 33 Debris",
56+
"groupType": "nameRegex",
57+
"data": "(COSMOS 2251|IRIDIUM 33) DEB"
58+
},
59+
{
60+
"id": "GlonassGroup",
61+
"name": "Glonass",
62+
"groupType": "nameRegex",
63+
"data": "GLONASS"
64+
},
65+
{
66+
"id": "GalileoGroup",
67+
"name": "Galileo",
68+
"groupType": "nameRegex",
69+
"data": "GALILEO"
70+
},
71+
{
72+
"id": "FunGroup",
73+
"name": "Fun",
74+
"groupType": "nameRegex",
75+
"data": "SYLDA"
76+
},
77+
{
78+
"id": "WestfordNeedlesGroup",
79+
"name": "Westford Needles",
80+
"groupType": "nameRegex",
81+
"data": "WESTFORD NEEDLES"
82+
},
83+
{
84+
"id": "SpaceXGroup",
85+
"name": "Space X",
86+
"groupType": "nameRegex",
87+
"data": "FALCON [19]"
88+
},
89+
{
90+
"id": "DebrisGroup",
91+
"name": "Debris",
92+
"groupType": "objectType",
93+
"data": "DEBRIS"
94+
},
95+
{
96+
"id": "Starlink",
97+
"name": "Starlink",
98+
"groupType": "nameRegex",
99+
"data": "STARLINK"
100+
},
101+
{
102+
"id": "Unknown",
103+
"name": "Unknown Objects",
104+
"groupType": "objectType",
105+
"data": "UNKNOWN"
106+
}
107+
]
108+
}

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const R2D = 80 / Math.PI;
44
const Events = {
55
satMovementChange: 'satMovementChange',
66
selectedSatChange: 'selectedSatChange',
7-
satHover: 'sathover',
7+
satHover: 'sathoverChange',
88
satDataLoaded: 'satdataloaded',
99
closeWindow: 'closeWindow',
1010
cruncherReady: 'cruncherReady'

src/hud/SearchBox.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ function doSearch (str: string) {
156156
}
157157

158158
if (satData[i].intlDes && satData[i].intlDes.indexOf(str) !== -1) {
159-
console.log(satData[i]);
160159
results.push({
161160
isIntlDes: true,
162161
strIndex: satData[i].intlDes.indexOf(str),

src/hud/index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,16 @@ function setHtml (selector: string, html: string) {
6767
}
6868
}
6969

70-
function onSelectedSatChange (event: any) {
71-
const { satellite } = event;
70+
function onSelectedSatChange (satellite: Record<string, any>) {
7271
if (satellite) {
7372
document.querySelector('#sat-infobox')?.classList.add('visible');
7473
setHtml('#sat-info-title', satellite.OBJECT_NAME);
7574
setHtml('#sat-intl-des', satellite.intlDes);
7675
setHtml('#sat-type', satellite.OBJECT_TYPE);
77-
setHtml('#sat-apogee', `${satellite.apogee.toFixed(0)} km`);
78-
setHtml('#sat-perigee', `${satellite.perigee.toFixed(0)} km`);
76+
setHtml('#sat-apogee', `${satellite.apogee?.toFixed(0)} km`);
77+
setHtml('#sat-perigee', `${satellite.perigee?.toFixed(0)} km`);
7978
setHtml('#sat-inclination', `${(satellite.inclination * R2D).toFixed(2)}°`);
80-
setHtml('#sat-period', `${satellite.period.toFixed(2)} min`);
79+
setHtml('#sat-period', `${satellite.period?.toFixed(2)} min`);
8180
} else {
8281
document.querySelector('#sat-infobox')?.classList.remove('visible');
8382
}
@@ -218,7 +217,7 @@ function initEventListeners () {
218217

219218
satelliteGroups?.reloadGroups();
220219

221-
// app.addEventListener(Events.selectedSatChange, onSelectedSatChange);
220+
viewer.addEventListener(Events.selectedSatChange, onSelectedSatChange);
222221

223222
// app.addEventListener(Events.satHover, onSatHover);
224223

src/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1+
import axios from 'axios';
12
import { createViewer } from './viewer/index';
2-
import config from './config';
3+
import defaultConfig from './config';
4+
import { setLogLevel } from './utils/logger';
35

46
import hud from './hud';
57

8+
async function loadConfig () {
9+
const response = await axios.get('config.json');
10+
let config = defaultConfig;
11+
if (response.data) {
12+
config = { ...defaultConfig, ...response.data };
13+
}
14+
return config;
15+
}
16+
617
async function main () {
18+
const config = await loadConfig();
19+
setLogLevel(config.logLevel);
20+
721
const viewer = createViewer(config);
822
await viewer.init();
923
viewer.animate();

src/utils/logger.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
/* eslint-disable no-console */
2-
import constants from '../config';
32

3+
const defaultLogLevel = 'debug';
44
const logLevels = ['error', 'warn', 'info', 'debug'];
5-
const enabledOutputs: Record<string, any> = {};
5+
66
let allOutputs: Record<string, any> = {};
7+
let globalLogger = new Proxy({
8+
logLevel: defaultLogLevel,
9+
enabledOutputs: {} as Record<string, any>,
10+
error: allOutputs.error,
11+
warn: allOutputs.warn,
12+
info: allOutputs.info,
13+
debug: allOutputs.debug,
14+
setLogLevel
15+
}, {});
716

817
function log (scope: any, level: string, output: (level: string, ...args: any) => void, ...args: any) {
918
if (scope.enabledOutputs[level]) {
@@ -19,34 +28,34 @@ function setLogLevel (level: string) {
1928
}
2029

2130
for (let i = 0; i < logLevels.length; i++) {
22-
enabledOutputs[logLevels[i]] = i <= levelIdx;
31+
globalLogger.enabledOutputs[logLevels[i]] = i <= levelIdx;
2332
}
2433
}
2534

2635
function getLogger () {
27-
return {
28-
error: allOutputs.error,
29-
warn: allOutputs.warn,
30-
info: allOutputs.info,
31-
debug: allOutputs.debug,
32-
setLogLevel
33-
};
36+
return globalLogger;
3437
}
3538

36-
function init (this: any) {
37-
allOutputs = {
38-
error: log.bind(this, { enabledOutputs }, 'error', console.error),
39-
warn: log.bind(this, { enabledOutputs }, 'warn', console.warn),
40-
info: log.bind(this, { enabledOutputs }, 'info', console.info),
41-
debug: log.bind(this, { enabledOutputs }, 'debug', console.debug)
42-
};
39+
function init () {
40+
const scope = globalLogger;
41+
42+
const enabledOutputs = scope.enabledOutputs;
4343

4444
for (let i = 0; i < logLevels.length; i++) {
4545
enabledOutputs[logLevels[i]] = true;
4646
}
47+
48+
allOutputs = {
49+
error: log.bind(scope, { enabledOutputs }, 'error', console.error),
50+
warn: log.bind(scope, { enabledOutputs }, 'warn', console.warn),
51+
info: log.bind(scope, { enabledOutputs }, 'info', console.info),
52+
debug: log.bind(scope, { enabledOutputs }, 'debug', console.debug)
53+
};
54+
55+
globalLogger = new Proxy({ ...globalLogger, ...allOutputs }, {});
4756
}
4857

4958
init();
50-
setLogLevel(constants.logLevel);
5159

5260
export default getLogger();
61+
export { setLogLevel };

src/viewer/Earth.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ class Earth implements SceneComponent {
118118
}
119119

120120
scene.add(this.group);
121+
122+
this.sphere.geometry.computeBoundingBox();
123+
this.sphere.geometry.computeBoundingSphere();
121124
}
122125

123126
update (): void {

0 commit comments

Comments
 (0)