-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathpositions.html
278 lines (253 loc) · 11.4 KB
/
positions.html
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<!DOCTYPE html>
<html>
<head>
<title>Celestial Body Positions</title>
<meta name="viewport" content="width=device-width,maximum-scale=2">
<link rel="stylesheet" href="astro_demo.css" />
</head>
<body id="main_content_wrap" class="inner">
<h1>Celestial Body Positions</h1>
<h2>Observer</h2>
<table cellpadding="5" cellspacing="0" border="1">
<tr>
<td>
<div>Date and Time:</div>
<div>
<input type="checkbox" id="AutoTimeCheckBox" onchange="OnToggleAutoTime()">
<label for="AutoTimeCheckBox">Automatic</label>
</div>
</td>
<td>
<input type="datetime" id="DateTimeBox" size="30">
</td>
</tr>
<tr>
<td>Latitude:</td>
<td><input type="text" id="EditLatitude" pattern="[\-\+]?\d+(\.\d*)?" size="10"></td>
</tr>
<tr>
<td>Longitude:</td>
<td><input type="text" id="EditLongitude" pattern="[\-\+]?\d+(\.\d*)?" size="10"></td>
</tr>
<tr>
<td>Elevation (m):</td>
<td><input type="text" id="EditElevation" pattern="[\-\+]?\d+(\.\d*)?" size="10"></td>
</tr>
</table>
<h2>Body Positions</h2>
<table cellpadding="5" cellspacing="0" id="CalcTable" border="1">
<tr>
<td>body</td>
<td class="NumHeader">RA</td>
<td class="NumHeader">DEC</td>
<td class="NumHeader">Az</td>
<td class="NumHeader">Alt</td>
</tr>
<tr>
<td>Sun</td>
<td id="Sun_ra" class="Numeric"></td>
<td id="Sun_dec" class="Numeric"></td>
<td id="Sun_az" class="Numeric"></td>
<td id="Sun_alt" class="Numeric"></td>
</tr>
<tr>
<td>Moon</td>
<td id="Moon_ra" class="Numeric"></td>
<td id="Moon_dec" class="Numeric"></td>
<td id="Moon_az" class="Numeric"></td>
<td id="Moon_alt" class="Numeric"></td>
</tr>
<tr>
<td>Mercury</td>
<td id="Mercury_ra" class="Numeric"></td>
<td id="Mercury_dec" class="Numeric"></td>
<td id="Mercury_az" class="Numeric"></td>
<td id="Mercury_alt" class="Numeric"></td>
</tr>
<tr>
<td>Venus</td>
<td id="Venus_ra" class="Numeric"></td>
<td id="Venus_dec" class="Numeric"></td>
<td id="Venus_az" class="Numeric"></td>
<td id="Venus_alt" class="Numeric"></td>
</tr>
<tr>
<td>Mars</td>
<td id="Mars_ra" class="Numeric"></td>
<td id="Mars_dec" class="Numeric"></td>
<td id="Mars_az" class="Numeric"></td>
<td id="Mars_alt" class="Numeric"></td>
</tr>
<tr>
<td>Jupiter</td>
<td id="Jupiter_ra" class="Numeric"></td>
<td id="Jupiter_dec" class="Numeric"></td>
<td id="Jupiter_az" class="Numeric"></td>
<td id="Jupiter_alt" class="Numeric"></td>
</tr>
<tr>
<td>Saturn</td>
<td id="Saturn_ra" class="Numeric"></td>
<td id="Saturn_dec" class="Numeric"></td>
<td id="Saturn_az" class="Numeric"></td>
<td id="Saturn_alt" class="Numeric"></td>
</tr>
<tr>
<td>Uranus</td>
<td id="Uranus_ra" class="Numeric"></td>
<td id="Uranus_dec" class="Numeric"></td>
<td id="Uranus_az" class="Numeric"></td>
<td id="Uranus_alt" class="Numeric"></td>
</tr>
<tr>
<td>Neptune</td>
<td id="Neptune_ra" class="Numeric"></td>
<td id="Neptune_dec" class="Numeric"></td>
<td id="Neptune_az" class="Numeric"></td>
<td id="Neptune_alt" class="Numeric"></td>
</tr>
<tr>
<td>Pluto</td>
<td id="Pluto_ra" class="Numeric"></td>
<td id="Pluto_dec" class="Numeric"></td>
<td id="Pluto_az" class="Numeric"></td>
<td id="Pluto_alt" class="Numeric"></td>
</tr>
</table>
<p>
This is a sample page for the open-source
<a href="https://github.com/cosinekitty/astronomy/">Astronomy Engine</a>.
All of the source code and documentation is available there.
Also, try using your browser's View Source command to look at how this page works.
</p>
</body>
<script src="astronomy.browser.js"></script>
<script>
function OnToggleAutoTime() {
const checkbox = document.getElementById('AutoTimeCheckBox');
const editbox = document.getElementById('DateTimeBox');
if (checkbox.checked) {
editbox.setAttribute('readonly', true);
} else {
editbox.removeAttribute('readonly');
}
}
window.onload = function() {
const StorageKey = 'AstroDemo.Options';
var Options;
function ParseDate(s) {
return new Date((s || '').replace(' ', 'T')); // Safari doesn't like the space character
}
function IsValidNumber(s) {
return typeof s === 'string' && /^[\-\+]?\d+(\.\d*)?$/.test(s);
}
function IsValidDate(s) {
const d = ParseDate(s);
return Number.isFinite(d.getTime());
}
function LoadOptions() {
let options;
try {
options = JSON.parse(window.localStorage.getItem(StorageKey));
} catch (e) {
}
if (!options) options = {};
if (!IsValidNumber(options.latitude)) options.latitude = '30';
if (!IsValidNumber(options.longitude)) options.longitude = '-90';
if (!IsValidNumber(options.elevation)) options.elevation = '0';
if (typeof options.automatic !== 'boolean') options.automatic = true;
if (!IsValidDate(options.date)) options.date = FormatDate(new Date());
return options;
}
function SaveOptions() {
try {
window.localStorage.setItem(StorageKey, JSON.stringify(Options));
} catch (e) {
}
}
function Init() {
let options = LoadOptions();
document.getElementById('EditLatitude').value = options.latitude;
document.getElementById('EditLongitude').value = options.longitude;
document.getElementById('EditElevation').value = options.elevation;
document.getElementById('DateTimeBox').value = options.date;
let checkbox = document.getElementById('AutoTimeCheckBox');
checkbox.checked = options.automatic;
OnToggleAutoTime();
return options;
}
function Pad(s, w) {
s = s.toFixed(0);
while (s.length < w) {
s = '0' + s;
}
return s;
}
function FormatDate(date) {
var year = Pad(date.getFullYear(), 4);
var month = Pad(1 + date.getMonth(), 2);
var day = Pad(date.getDate(), 2);
var hour = Pad(date.getHours(), 2);
var minute = Pad(date.getMinutes(), 2);
var second = Pad(date.getSeconds(), 2);
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
}
function FormatCoord(x) {
return x.toFixed(2);
}
const BodyList = [
'Sun', 'Moon', 'Mercury', 'Venus', 'Mars',
'Jupiter', 'Saturn', 'Uranus', 'Neptune', 'Pluto'
];
function UpdateScreen() {
const autotime = document.getElementById('AutoTimeCheckBox').checked;
const timebox = document.getElementById('DateTimeBox');
let text_latitude = document.getElementById('EditLatitude').value;
let text_longitude = document.getElementById('EditLongitude').value;
let text_elevation = document.getElementById('EditElevation').value;
let date;
if (autotime) {
// Automatically update the date/time every second, using the computer's clock.
date = new Date();
timebox.value = FormatDate(date);
} else {
// Try to parse a date/time from the user's input.
date = ParseDate(timebox.value);
}
if (!IsValidDate(timebox.value) || !IsValidNumber(text_latitude) || !IsValidNumber(text_longitude) || !IsValidNumber(text_elevation)) {
// Bail out until user corrects problems in the observer coordinates.
// Gray out the whole table so the user knows there is something wrong.
document.getElementById('CalcTable').style.display = 'none';
} else {
document.getElementById('CalcTable').style.display = '';
let latitude = parseFloat(text_latitude);
let longitude = parseFloat(text_longitude);
let elevation = parseFloat(text_elevation);
if (latitude !== Options.latitude || longitude !== Options.longitude || elevation !== Options.elevation || Options.automatic !== autotime) {
Options = {
latitude: text_latitude,
longitude: text_longitude,
elevation: text_elevation,
automatic: autotime,
date: timebox.value
};
SaveOptions();
}
let observer = new Astronomy.Observer(latitude, longitude, elevation);
for (let body of BodyList) {
let equ_2000 = Astronomy.Equator(body, date, observer, false, true);
let equ_ofdate = Astronomy.Equator(body, date, observer, true, true);
let hor = Astronomy.Horizon(date, observer, equ_ofdate.ra, equ_ofdate.dec, 'normal');
document.getElementById(`${body}_ra`).innerText = FormatCoord(equ_2000.ra);
document.getElementById(`${body}_dec`).innerText = FormatCoord(equ_2000.dec);
document.getElementById(`${body}_az`).innerText = FormatCoord(hor.azimuth);
document.getElementById(`${body}_alt`).innerText = FormatCoord(hor.altitude);
}
}
setTimeout(UpdateScreen, 1000);
}
Options = Init();
UpdateScreen();
}
</script>
</html>