Skip to content

Commit

Permalink
Merge pull request #44 from thkruz/fix-find-all-satellites-from-launch
Browse files Browse the repository at this point in the history
Fix find all satellites from launch
  • Loading branch information
ajmas authored Dec 21, 2023
2 parents 461a682 + c9f15f2 commit 48eb5ca
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/hud/HudWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Window {
this.element.classList.add('visible');
this.element.classList.remove('hidden');
this.windowManager.bringWindowToFront(this);
this.fireEvent('open', {});
}

close () {
Expand All @@ -39,6 +40,7 @@ class Window {
this.element.classList.remove('active');
this.element.classList.remove('visible');
this.element.classList.add('hidden');
this.fireEvent('close', {});
}

isOpen () {
Expand Down
23 changes: 21 additions & 2 deletions src/hud/HudWindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ class WindowManager {
}
}

/**
* Retrieves the window with the specified windowId.
*
* @param windowId - The unique identifier of the window.
*/
getWindow (windowId: string): HudWindow | undefined {
return this.windowsById[windowId];
}

registerWindow (windowId: string, options: Record<string, any> = {}) {
const window = new HudWindow(windowId, options);
window.setWindowManager(this);
Expand Down Expand Up @@ -72,8 +81,18 @@ class WindowManager {
if (firstOpen && topWindow) {
const location = topWindow.getLocation();
if (location) {
x = location.x + newWindowOffset;
y = location.y + newWindowOffset;
// If location is on right side of screen, open new window to the left side
if (location.x > window.innerWidth / 2) {
x = location.x - newWindowOffset - 300;
} else {
x = location.x + newWindowOffset;
}
// If location is on bottom half of screen, open new window to the top
if (location.y > window.innerHeight / 2) {
y = location.y - newWindowOffset - 300;
} else {
y = location.y + newWindowOffset;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/hud/SearchBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ function doSearch (str: string) {
const satelliteGroups = viewer.getSatelliteGroups();
if (satelliteGroups) {
satelliteGroups.selectGroup(dispGroup);
viewer.setSelectedSatelliteGroup(dispGroup);
}

fillResultBox(results, str);
Expand Down
8 changes: 8 additions & 0 deletions src/hud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ function init (viewerInstance: Viewer) {
windowManager.registerWindow('help-window');
windowManager.registerWindow('groups-window');
windowManager.registerWindow('search-window');
windowManager.getWindow('search-window')?.addEventListener('close', () => {
viewer.getSatelliteGroups()?.clearSelect();
viewer.setSelectedSatelliteGroup();
const listItems = document.querySelectorAll('#groups-display>li');
for (const item of listItems) {
item.classList.remove('selected');
}
});

searchBox.init(viewer, windowManager);

Expand Down
2 changes: 2 additions & 0 deletions src/viewer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,12 @@ class Viewer {
let satIdx = -1;
let satellite;
if (satelliteIds && satelliteIds.length > 0) {
// This is the first possible satellite, it is the closest to the camera
satIdx = satelliteIds[0];
satellite = this.satelliteStore?.getSatellite(satIdx);
}

this.selectedSatelliteIdx = satIdx;
this.satellites?.setSelectedSatellite(satIdx);
this.orbits?.setSelectedSatellite(satIdx);
this.eventManager.fireEvent('selectedSatChange', satellite);
Expand Down

0 comments on commit 48eb5ca

Please sign in to comment.