-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathup.html
389 lines (351 loc) · 17.9 KB
/
up.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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<!DOCTYPE html>
<!-- This is a very simple example of using Web WorldWind. -->
<html>
<head lang="en">
<meta charset="UTF-8">
<title>WorldWind Example</title>
<link href="upStyle.css" rel="stylesheet">
<!-- Include the Web WorldWind library. -->
<script src="https://files.worldwind.arc.nasa.gov/artifactory/web/0.9.0/worldwind.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<button id="sat-view-btn" onclick="changeView()" value="Satelite View!">Change View</button>
<button id="rewind" onclick="console.log('rew')">Rewind</button>
<div id="wwd-div">
<canvas id="wwd-canvas">
Your browser does not support HTML5 Canvas.
</canvas>
</div>
<script>
// Register an event listener to be called when the page is loaded.
window.addEventListener("load", eventWindowLoaded, false);
// The sattelite id that this page has centered
var currentSatID;
// boolean to indicate wheter I'm on sat view or third person View. Default is third person
var satView = false;
// Create a WorldWindow for the canvas.
var wwd = new WorldWind.WorldWindow("wwd-canvas");
// delay config in millis
var DELAY = 1000;
var rewind = false;
// it counts the number of iterations performed. Since we get the future positions from the API in chunks of 300 we have to transact with the API and
// reset the number of iterations every time it reaches 300.
var iteration = 0;
// arrays to store future future locations of the current sat, so the user can press fast forward.
// also we dont have to call the API every second since we store future positions in the arrays.
var currLat=[]; //latitude
var currLong=[]; // longitude
var currAlt=[] //altitude
var currName; // sat name
// store the coordinates of the neighboring satelites in multidimensional arrrays
var neighborLat = [];
var neighborLong = [];
var neighborAlt = [];
// store the names in an 1-d array
var neighborName = [];
// store the id's of the neighbors to make api calls
var neighborID = [];
function eventWindowLoaded() {
// decode the ID from the URL.
var url = document.location.href,
params = url.split('?')[1].split('&'),
data = [], tmp;
for (var i = 0, l = params.length; i < l; i++) {
tmp = params[i].split('=');
data[tmp[0]] = tmp[1];
}
currentSatID = data.id;
var neighborCount = data.num; //number of neighbors to plot
// fill the neighborID array
for (var i=0; i<neighborCount; i++) {
var x = "id" + i;
neighborID[i] = data[x];
console.log(neighborID[i]);
}
// make a request for current sat
/* var request = {
"async": false,
"crossDomain": true,
"url": "https://www.n2yo.com/rest/v1/satellite/positions/" + currentSat + "/37.10/22.10/0/300/&apiKey=FR2XVF-WR3JRJ-Z9UGV4-4KBZ",
"method": "GET"
}
$.ajax(request).done(function (response) {
console.log(response.info.satname);
// fill the arrrays with a chunk of 300 future positions
var i;
for (i = 0; i < 300; i++) {
currLat[i] = response.positions[i].satlatitude;
currLong[i] = response.positions[i].satlongitude;
currAlt[i] = response.positions[i].sataltitude * 1000; //convert km to m
}
currName = response.info.satname;
}); */
$.ajax({
data: {cmd:"positions",
id:currentSatID,
obs_lat:"37",
obs_lng:"22",
obs_alt:"0",
sec:"300"},
url: '../handle_api_requests.php',
method: 'POST', // or GET
async: false,
success: function(msg) {
var response = JSON.parse(msg);
console.log(msg);
console.log(response);
console.log(response.info.satname);
// fill the arrrays with a chunk of 300 future positions
for (var i = 0; i < 300; i++) {
currLat[i] = response.positions[i].satlatitude;
currLong[i] = response.positions[i].satlongitude;
currAlt[i] = response.positions[i].sataltitude * 1000; //convert km to m
}
currName = response.info.satname;
}
});
// make a loop to request for coordinates for all neighbors
for (var neighbor=0; neighbor<neighborCount; neighbor++) {
// make a request for current neighbor
/*var request = {
"async": false,
"crossDomain": true,
"url": "https://www.n2yo.com/rest/v1/satellite/positions/" + neighborID[neighbor] + "/37.10/22.10/0/300/&apiKey=FR2XVF-WR3JRJ-Z9UGV4-4KBZ",
"method": "GET"
}
$.ajax(request).done(function (response) {
console.log(response.info.satname);
// instantiate the arrays for this neighbor
neighborLat[neighbor] = [];
neighborLong[neighbor] = [];
neighborAlt[neighbor] = [];
// fill the arrrays with a chunk of 300 future positions
for (var i = 0; i < 300; i++) {
neighborLat[neighbor][i] = response.positions[i].satlatitude;
neighborLong[neighbor][i] = response.positions[i].satlongitude;
neighborAlt[neighbor][i] = response.positions[i].sataltitude * 1000; //convert km to m
}
neighborName[neighbor] = response.info.satname;
});*/
$.ajax({
data: {cmd:"positions",
id:neighborID[neighbor],
obs_lat:"37",
obs_lng:"22",
obs_alt:"2",
sec:"300"},
url: '../handle_api_requests.php',
method: 'POST', // or GET
async: false,
success: function(msg) {
var response = JSON.parse(msg);
console.log(response.info.satname);
// instantiate the arrays for this neighbor
neighborLat[neighbor] = [];
neighborLong[neighbor] = [];
neighborAlt[neighbor] = [];
// fill the arrrays with a chunk of 300 future positions
for (var i = 0; i < 300; i++) {
neighborLat[neighbor][i] = response.positions[i].satlatitude;
neighborLong[neighbor][i] = response.positions[i].satlongitude;
neighborAlt[neighbor][i] = response.positions[i].sataltitude * 1000; //convert km to m
}
neighborName[neighbor] = response.info.satname;
}
});
}
// Add some image layers to the WorldWindow's globe.
wwd.addLayer(new WorldWind.BMNGOneImageLayer());
wwd.addLayer(new WorldWind.BMNGLandsatLayer());
// create a placemark layer
var placemarkLayer = new WorldWind.RenderableLayer("Placemarks");
// set the placemark for the current sat
var sat = new WorldWind.Placemark(new WorldWind.Position(currLat[0], currLong[0] , currAlt[0]), true);
sat.label = currName;
// set an array of placemarks for the neighboring sats.
var neighborSat = [];
for (var i=0; i<neighborCount; i++) {
neighborSat[i] = new WorldWind.Placemark(new WorldWind.Position(neighborLat[i][0], neighborLong[i][0] , neighborAlt[0]), true);
neighborSat[i].label = neighborName[i];
}
// set attributes
var attributes = sat.attributes;
attributes.drawLeaderLine = true;
attributes.labelAttributes.color = WorldWind.Color.YELLOW;
attributes.imageSource = "static/satellite.png";
attributes.labelAttributes.offset = new WorldWind.Offset(
WorldWind.OFFSET_FRACTION, 0.5,
WorldWind.OFFSET_FRACTION, -1.0);
attributes.imageScale = 3;
attributes.labelAttributes.font = new WorldWind.Font(50);
placemarkLayer.addRenderable(sat);
// set attributes for neighborSat
for (var i=0; i<neighborCount; i++) {
var attributes = neighborSat[i].attributes;
attributes.imageSource = "static/satellite.png";
attributes.drawLeaderLine = true;
attributes.imageScale = 3;
placemarkLayer.addRenderable(neighborSat[i]);
}
wwd.addLayer(placemarkLayer);
// Add a compass, a coordinates display and some view controls to the WorldWindow.
wwd.addLayer(new WorldWind.CompassLayer());
wwd.addLayer(new WorldWind.CoordinatesDisplayLayer(wwd));
wwd.addLayer(new WorldWind.ViewControlsLayer(wwd));
wwd.navigator.tilt = 60;
// wwd.navigator.range = 5000000;
wwd.goTo(new WorldWind.Location(sat.position.latitude, sat.position.longitude));
// loop to update the position of the sattelites
function myLoop() { // create a loop function
setTimeout(function() { // call a setTimeout when the loop is called
if (rewind) { // TO-DO :: if rewind go back. Currently this doesnt work proeprly
sat1.position = new WorldWind.Position(sat1.position.latitude -1.0/100, sat1.position.longitude-1.0/100, 500000);
wwd.goTo(new WorldWind.Position(sat1.position.latitude, sat1.position.longitude, 3000000));
}
else { // if not rewind move normally
// if it is the 300th iteration, transact again and fill the arrays with new positions.
if (iteration==300) {
/*var newRequest = {
"async": true,
"crossDomain": true,
"url": "https://www.n2yo.com/rest/v1/satellite/positions/" + currentSat + "/37.10/22.10/0/300/&apiKey=FR2XVF-WR3JRJ-Z9UGV4-4KBZ",
"method": "GET"
}
$.ajax(newRequest).done(function (response) {
console.log(response.info.satname);
for (var i=0; i<300; i++) {
currLat[i] = response.positions[i].satlatitude;
currLong[i] = response.positions[i].satlongitude;
currAlt[i] = response.positions[i].sataltitude * 1000;
}
});*/
$.ajax({
data: {cmd:"positions",
id:currentSatID,
obs_lat:"37",
obs_lng:"22",
obs_alt:"0",
sec:"300"},
url: '../handle_api_requests.php',
method: 'POST', // or GET
async: false,
success: function(msg) {
var response = JSON.parse(msg);
console.log(response.info.satname);
for (var i=0; i<300; i++) {
currLat[i] = response.positions[i].satlatitude;
currLong[i] = response.positions[i].satlongitude;
currAlt[i] = response.positions[i].sataltitude * 1000;
}
}
});
// make a loop to request for coordinates for all neighbors
for (var neighbor=0; neighbor<neighborCount; neighbor++) {
// make a request for current neighbor
/* var request = {
"async": false,
"crossDomain": true,
"url": "https://www.n2yo.com/rest/v1/satellite/positions/" + neighborID[neighbor] + "/37.10/22.10/0/300/&apiKey=FR2XVF-WR3JRJ-Z9UGV4-4KBZ",
"method": "GET"
}
$.ajax(request).done(function (response) {
console.log(response.info.satname);
// fill the arrrays with a chunk of 300 future positions
for (var i = 0; i < 300; i++) {
neighborLat[neighbor][i] = response.positions[i].satlatitude;
neighborLong[neighbor][i] = response.positions[i].satlongitude;
neighborAlt[neighbor][i] = response.positions[i].sataltitude * 1000; //convert km to m
}
});*/
$.ajax({
data: {cmd:"positions",
id:neighborID[neighbor],
obs_lat:"37",
obs_lng:"22",
obs_alt:"0",
sec:"300"},
url: '../handle_api_requests.php',
method: 'POST', // or GET
async: false,
success: function(msg) {
var response = JSON.parse(msg);
console.log(response.info.satname);
// fill the arrrays with a chunk of 300 future positions
for (var i = 0; i < 300; i++) {
neighborLat[neighbor][i] = response.positions[i].satlatitude;
neighborLong[neighbor][i] = response.positions[i].satlongitude;
neighborAlt[neighbor][i] = response.positions[i].sataltitude * 1000; //convert km to m
}
}
});
}
// reset the iterations
iteration = 0;
}
// set the sat position
sat.position = new WorldWind.Position(currLat[iteration], currLong[iteration], currAlt[iteration]);
// set neihbor positions
for (var i=0; i<neighborCount; i++) {
neighborSat[i].position = new WorldWind.Position(neighborLat[i][iteration], neighborLong[i][iteration], neighborAlt[i][iteration]);
}
// if it is on third person view go to the sat location with an arbiatry scaling in altitude
if(!satView) {
wwd.goTo(new WorldWind.Position(sat.position.latitude, sat.position.longitude, currAlt[iteration]*6));
}
// else go to the sattelite location with its own altitude to simulate its View
else if (satView) {
wwd.goTo(new WorldWind.Position(sat.position.latitude, sat.position.longitude, currAlt[iteration]));
}
}
iteration++; // increment the counter
if (true) {
myLoop(); // .. again which will trigger another
} // .. setTimeout()
}, DELAY)
}
myLoop(); // start the loop */
}
// The common gesture-handling function.
var handleClick = function (recognizer) {
// Obtain the event location.
var x = recognizer.clientX,
y = recognizer.clientY;
// Perform the pick. Must first convert from window coordinates to canvas coordinates, which are
// relative to the upper left corner of the canvas rather than the upper left corner of the page.
var pickList = wwd.pick(wwd.canvasCoordinates(x, y));
// If only one thing is picked and it is the terrain, tell the WorldWindow to go to the picked location.
if (pickList.objects.length === 1 && pickList.objects[0].isTerrain) {
var position = pickList.objects[0].position;
wwd.goTo(new WorldWind.Location(position.latitude, position.longitude));
}
else {
wwd.goTo(new WorldWind.Position(22, 37, 3000000));
}
};
// Listen for mouse clicks.
var clickRecognizer = new WorldWind.ClickRecognizer(wwd, handleClick);
// Listen for taps on mobile devices.
var tapRecognizer = new WorldWind.TapRecognizer(wwd, handleClick);
// takes to user to see from the sats location
function changeView() {
// if you are on third person view switch to sat view
if (!satView) {
satView = true;
this.value = "Third Person View";
// change navigator settings to make the navigator look straight down as the sattelite would, centered right below the sattelite
wwd.navigator.tilt = 0; // looks straight down
wwd.navigator.range = currAlt[iteration]; // sets altitude to the sattelite altitude
}
// else switch back to third person
else {
satView = false;
this.value = "Sattelites View!";
// restore default navigator settings
wwd.navigator.tilt = 60;
wwd.navigator.range = currAlt[iteration]*6;
}
}
</script>
</body>
</html>