This repository was archived by the owner on Sep 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhelios.ts
More file actions
84 lines (77 loc) · 2.99 KB
/
Copy pathhelios.ts
File metadata and controls
84 lines (77 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import Config from "../Configuration.js";
import { ToDateString } from "../common/dates";
import { ToCoordinates } from "./common";
import { Favorite, Favorites } from "./favorites";
import { PFSS, ParsePfssBundle } from "../common/pfss";
class Helios {
/**
* Returns the observer position of a jp2 image
* @param {number} id ID of the jp2 image
* @returns Coordinates
*/
static async GetJp2Observer(id) {
let api_url = Config.helios_api_url + "observer/position/" + id;
let result = await fetch(api_url);
let data = await result.json();
if (data.hasOwnProperty("error")) {
throw data.error;
}
return ToCoordinates(data);
}
static async SaveScene(favorite: Favorite): Promise<number> {
let copy: any = window.structuredClone(favorite);
copy.created_at = ToDateString(copy.created_at);
copy.start = ToDateString(copy.start);
copy.end = ToDateString(copy.end);
for (let i = 0; i < copy.layers.length; i++) {
copy.layers[i].start = ToDateString(copy.layers[i].start as Date);
copy.layers[i].end = ToDateString(copy.layers[i].end as Date);
}
let response = await fetch(Config.helios_api_url + "scene", {
method: "POST", // *GET, POST, PUT, DELETE, etc.
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(copy), // body data type must match "Content-Type" header
});
let result = await response.json();
if (result.hasOwnProperty("error")) {
throw result["error"];
}
return result.id;
}
static async LoadScene(id: number): Promise<Favorite> {
let response = await fetch(Config.helios_api_url + "scene/" + id);
let data = await response.json();
return Favorites.RestoreDates([data])[0];
}
static async GetRecentlyShared(): Promise<Favorite[]> {
let response = await fetch(Config.helios_api_url + "scene/latest/10");
let data = await response.json();
return Favorites.RestoreDates(data.scenes);
}
static async get_field_lines_gong(
date: Array<Date>,
detail: number = 50
): Promise<PFSS[]> {
// Construct a query string in the form date=<date1>&date=<date2>...
let date_strings = date.map((d) => "date=" + ToDateString(d));
let query_params = date_strings.join("&");
let url =
Config.helios_api_url +
"pfss/gong/?detail=" +
detail +
"&" +
query_params;
let response = await fetch(url);
let reader = response.body.getReader();
return await ParsePfssBundle(reader);
}
static async GetEarthPosition(date: Date) {
let url = Config.helios_api_url + "/earth/" + ToDateString(date);
let response = await fetch(url);
let data = await response.json();
return ToCoordinates(data);
}
}
export { Helios };