Skip to content

Commit 27e6f58

Browse files
Updated czml_viewer to get obs_id from URL
1 parent d7fb04d commit 27e6f58

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

cesium/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@
3939

4040
<body>
4141
<div id="buttonContainer" style="position:absolute; left: 0px; z-index:1;">
42-
<button class="cesium-button button-czml-load" data-file="http://localhost:8080/czml/obs/1276">Observation 1276</button>
43-
<button class="cesium-button button-clear-all">Clear</button>
42+
<!-- The following buttons can be used for debugging CZML observation loading.
43+
<button class="cesium-button button-czml-load" data-file="http://localhost:8080/czml/obs/1276">Observation 1276</button>
44+
<button class="cesium-button" id="clear">Clear</button> -->
45+
<input class="cesium" value="Observation id" type="number" id="obs-id"></input>
46+
<button class="cesium-button" id="load-obs">Load observation</button>
4447
<button class="cesium-button button-frame-selector" data-names="Inertial (ECI),Fixed (ECEF)">Reference frame:Fixed (ECEF)</button>
4548
</div>
4649
<div id="cesiumContainer">

cesium/src/utils/czml_viewer.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,44 @@
99

1010
import * as Cesium from "cesium";
1111

12+
const CZML_URL = 'http://localhost:8080/czml/obs/';
13+
1214
export function czmlViewer(viewer: Cesium.Viewer) {
1315

14-
// This updates constellation buttons
16+
// This updates the CZML load buttons
1517
const czmlButtons = [...document.querySelectorAll(".button-czml-load")] as HTMLButtonElement[];
1618
czmlButtons.forEach(btn => {
1719
const f = btn.dataset["file"] as string;
1820

1921
btn.onclick = () => loadCzml(viewer, f);
2022
});
2123

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 = () => {
2635
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+
}
2950
}
3051

3152
function loadCzml(viewer: Cesium.Viewer, czml: string) {

0 commit comments

Comments
 (0)