|
9 | 9 |
|
10 | 10 | import * as Cesium from "cesium";
|
11 | 11 |
|
| 12 | +const CZML_URL = 'http://localhost:8080/czml/obs/'; |
| 13 | + |
12 | 14 | export function czmlViewer(viewer: Cesium.Viewer) {
|
13 | 15 |
|
14 |
| - // This updates constellation buttons |
| 16 | + // This updates the CZML load buttons |
15 | 17 | const czmlButtons = [...document.querySelectorAll(".button-czml-load")] as HTMLButtonElement[];
|
16 | 18 | czmlButtons.forEach(btn => {
|
17 | 19 | const f = btn.dataset["file"] as string;
|
18 | 20 |
|
19 | 21 | btn.onclick = () => loadCzml(viewer, f);
|
20 | 22 | });
|
21 | 23 |
|
22 |
| - // Find all clear-all buttons |
23 |
| - const clearButtons = [...document.querySelectorAll(".button-clear-all")] as HTMLButtonElement[]; |
24 |
| - clearButtons.forEach(btn => { |
25 |
| - btn.onclick = () => { |
| 24 | + // This adds load observation onclick callback to Show observation |
| 25 | + const czmlLoad = document.getElementById("load-obs") as HTMLButtonElement; |
| 26 | + czmlLoad.onclick = () => { |
| 27 | + let obs_id = (document.getElementById("obs-id") as HTMLInputElement).value; |
| 28 | + loadCzml(viewer, CZML_URL + obs_id); |
| 29 | + }; |
| 30 | + |
| 31 | + // Find the clear button and set the callback to clear all datasources (remove all loaded observations) |
| 32 | + const clearButton = document.getElementById("clear") as HTMLButtonElement; |
| 33 | + if (clearButton) { |
| 34 | + clearButton.onclick = () => { |
26 | 35 | viewer.dataSources.removeAll();
|
27 |
| - } |
28 |
| - }) |
| 36 | + }; |
| 37 | + } |
| 38 | + |
| 39 | + // Find if there's observation number passed in URL. If there is, load the CZML file. |
| 40 | + const queryString = window.location.search; |
| 41 | + const urlParams = new URLSearchParams(queryString); |
| 42 | + if (urlParams.has('obs_id')) { |
| 43 | + console.log("Loading observation " + urlParams.get('obs_id')); |
| 44 | + loadCzml(viewer, CZML_URL + urlParams.get('obs_id')); |
| 45 | + |
| 46 | + // Also set up the input field to the observation id we just loaded. |
| 47 | + const obs_id = document.getElementById("obs-id") as HTMLInputElement; |
| 48 | + obs_id.value = urlParams.get('obs_id') as string; |
| 49 | + } |
29 | 50 | }
|
30 | 51 |
|
31 | 52 | function loadCzml(viewer: Cesium.Viewer, czml: string) {
|
|
0 commit comments