diff --git a/src/hud/HudWindow.ts b/src/hud/HudWindow.ts index c43e48a..9e8d2fe 100644 --- a/src/hud/HudWindow.ts +++ b/src/hud/HudWindow.ts @@ -29,6 +29,7 @@ class Window { this.element.classList.add('visible'); this.element.classList.remove('hidden'); this.windowManager.bringWindowToFront(this); + this.fireEvent('open', {}); } close () { @@ -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 () { diff --git a/src/hud/HudWindowManager.ts b/src/hud/HudWindowManager.ts index e5dd455..a4fb719 100644 --- a/src/hud/HudWindowManager.ts +++ b/src/hud/HudWindowManager.ts @@ -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 = {}) { const window = new HudWindow(windowId, options); window.setWindowManager(this); @@ -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; + } } } diff --git a/src/hud/SearchBox.ts b/src/hud/SearchBox.ts index d9347d4..8c96a91 100644 --- a/src/hud/SearchBox.ts +++ b/src/hud/SearchBox.ts @@ -184,6 +184,7 @@ function doSearch (str: string) { const satelliteGroups = viewer.getSatelliteGroups(); if (satelliteGroups) { satelliteGroups.selectGroup(dispGroup); + viewer.setSelectedSatelliteGroup(dispGroup); } fillResultBox(results, str); diff --git a/src/hud/index.ts b/src/hud/index.ts index 33303e3..91f0f72 100644 --- a/src/hud/index.ts +++ b/src/hud/index.ts @@ -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); diff --git a/src/viewer/index.ts b/src/viewer/index.ts index 4507a52..f77bbd7 100644 --- a/src/viewer/index.ts +++ b/src/viewer/index.ts @@ -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);