-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
621 lines (460 loc) · 16.1 KB
/
main.js
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
var NUMBER_OF_POINTS = 250.0; // Accurate within 1 point
var NUMBER_OF_SECONDS_IN_DAY = 86400.0;
var SECONDS_TO_HOURS = 0.000277778;
var HOURS_TO_MINUTES = 60;
var METERS_TO_FEET = 3.28084;
var METERS_TO_NM = 0.000539957;
$(document).ready(function() {
Cesium.BingMapsApi.defaultKey="WCDFG1t7dCho3pYtjhP3~9TtLhJwfh4TmoCzzEsWmJg~ArVbBS52XqbPzY8aDjPfjh1biz_l3e8vI6sseb6k7TuH9omW5MjD3v6ex6i2dKjy";
var viewer = new Cesium.Viewer('cesiumContainer');
// Set Cesium Key and Viewer
var flight;
var StartTime;
var EndTime;
var usedEntites = [];
$(".setEndTime").hide();
$(".toggleFlightPath").hide();
$(".toggleRealCourse").hide();
$(".toggleTargetCourse").hide();
$(".resultsdiv").hide();
function getGroundPosition(point) {
var cartoCoords = Cesium.Ellipsoid.WGS84.cartesianToCartographic(point);
cartoCoords.height = 0;
cartesianPoint = Cesium.Ellipsoid.WGS84.cartographicToCartesian(cartoCoords);
return cartesianPoint;
}
// function segmentLine(startPositon, endPosition, numberOfPoints) {
// var deltaKeys = ["x", "y", "z"];
// var deltas = [];
// var valueAdded = [];
// var results = [];
// for (var i = 0; i< deltaKeys.length; i++) {
// deltas.push((endPosition[deltaKeys[i]] - startPositon[deltaKeys[i]])/numberOfPoints);
// valueAdded.push(0.0);
// }
// for (var i = 0; i < numberOfPoints; i++ ) {
// additions = [];
// for (var j = 0; j < deltaKeys.length; j++) {
// additions[j] = valueAdded[j] + deltas[j];
// valueAdded[j] += deltas[j];
// };
// results.push(new Cesium.Cartesian3(additions[0], additions[1], additions[2]));
// }
// return results;
// }
function drawGroundPath(positions, color) {
var entites = [];
for (var i = 0; i < positions.length - 1; i++) {
entites.push(viewer.entities.add({
name: 'Height',
polygon: {
hierarchy: [positions[i], positions[i+1], getGroundPosition(positions[i + 1]), getGroundPosition(positions[i])],
material: color,
height: 0,
extrudedHeight: Cesium.Ellipsoid.WGS84.cartesianToCartographic(positions[i]).height
}
}));
}
return entites;
}
function toggleVisibilityOfElementsInArray(array) {
for (var i = 0; i<array.length; i++) {
array[i].show = !array[i].show;
}
}
var dataTitles = [
{
dataName: "initialAltitude",
title: "Initial Altitude: ",
unit: " feet MSL"
}, {
dataName: "finalAltitude",
title: "Final Altitude: ",
unit: " feet MSL"
}, {
dataName: "averageAltitude",
title: "Average Altitude: ",
unit: " feet MSL"
}, {
dataName: "minAlt",
title: "Minimum Altitude: ",
unit: " feet MSL"
}, {
dataName: "maxAlt",
title: "Maximum Altitude: ",
unit: " feet MSL"
}, {
dataName: "initialSpeed",
title: "Initial Speed: ",
unit: " knots"
}, {
dataName: "finalSpeed",
title: "Final Speed: ",
unit: " knots"
}, {
dataName: "averageSpeed",
title: "Average Speed: ",
unit: " knots"
}, {
dataName: "minSpeed",
title: "Minimum Speed: ",
unit: " knots"
}, {
dataName: "maxSpeed",
title: "Maximum Speed: ",
unit: " knots"
}, {
dataName: "distance",
title: "Total Distance: ",
unit: " nautical miles"
}, {
dataName: "initialVerticalSpeed",
title: "Initial Vertical Speed: ",
unit: " feet per minute"
}, {
dataName: "finalVerticalSpeed",
title: "Final Vertical Speed: ",
unit: " feet per minute"
}, {
dataName: "averageVerticalSpeed",
title: "Average Vertical Speed:" ,
unit: " feet per minute"
}, {
dataName: "maxVerticalSpeed",
title: "Max Vertical Speed: ",
unit: " feet per minute"
}, {
dataName: "minVerticalSpeed",
title: "Minimum Vertical Speed: ",
unit: " feet per minute"
}
]
function buildDataTitles(data) {
var result = "";
for (var i = 0; i < dataTitles.length; i++) {
dataTitle = dataTitles[i];
result += dataTitle.title + Math.trunc(data[dataTitle.dataName]) + dataTitle.unit + "\n\n";
}
return result;
}
var maneuvers = {
straightAndLevel: function(data, startTime, endTime) {
targetCourse = viewer.entities.add({
name : 'Target Course',
polyline : {
positions : [data.positions[0], data.positions[data.positions.length-1]],
width : 5,
material : Cesium.Color.BLUE
}
});
actualCourse = viewer.entities.add({
name : 'Actual Course',
polyline: {
positions: data.positions,
material: Cesium.Color.RED
}
});
actualCourseGroundLines = drawGroundPath(data.positions, Cesium.Color.RED.withAlpha(0.5));
usedEntites.push(targetCourse);
usedEntites.push(actualCourse);
for (var i = 0; i<actualCourseGroundLines.length; i++) {
usedEntites.push(actualCourseGroundLines[i]);
}
$(".toggleRealCourse").on("click", function() {
actualCourse.show = !actualCourse.show;
toggleVisibilityOfElementsInArray(actualCourseGroundLines);
});
$(".toggleTargetCourse").on("click", function() {
targetCourse.show = !targetCourse.show;
});
var result = "STRAIGHT AND LEVEL FLIGHT STATISTICS: \n\n" + buildDataTitles(data);
$(".results").text(result);
$(".results").html($(".results").html().replace(/\n/g,'<br>'));
}, climb: function(data, startTime, endTime) {
targetCourse = viewer.entities.add({
name : 'Target Course',
polyline : {
positions : [data.positions[0], data.positions[data.positions.length-1]],
width : 5,
material : Cesium.Color.BLUE
}
});
actualCourse = viewer.entities.add({
name : 'Actual Course',
polyline: {
positions: data.positions,
material: Cesium.Color.RED
}
});
actualCourseGroundLines = drawGroundPath(data.positions, Cesium.Color.RED.withAlpha(0.5));
usedEntites.push(targetCourse);
usedEntites.push(actualCourse);
for (var i = 0; i<actualCourseGroundLines.length; i++) {
usedEntites.push(actualCourseGroundLines[i]);
}
$(".toggleRealCourse").on("click", function() {
actualCourse.show = !actualCourse.show;
toggleVisibilityOfElementsInArray(actualCourseGroundLines);
});
$(".toggleTargetCourse").on("click", function() {
targetCourse.show = !targetCourse.show;
});
var result = "CLIMB STATISTICS: \n\n" + buildDataTitles(data);
$(".results").text(result);
$(".results").html($(".results").html().replace(/\n/g,'<br>'));
}, descent: function(data, startTime, endTime) {
targetCourse = viewer.entities.add({
name : 'Target Course',
polyline : {
positions : [data.positions[0], data.positions[data.positions.length-1]],
width : 5,
material : Cesium.Color.BLUE
}
});
actualCourse = viewer.entities.add({
name : 'Actual Course',
polyline: {
positions: data.positions,
material: Cesium.Color.RED
}
});
actualCourseGroundLines = drawGroundPath(data.positions, Cesium.Color.RED.withAlpha(0.5));
usedEntites.push(targetCourse);
usedEntites.push(actualCourse);
for (var i = 0; i<actualCourseGroundLines.length; i++) {
usedEntites.push(actualCourseGroundLines[i]);
}
$(".toggleRealCourse").on("click", function() {
actualCourse.show = !actualCourse.show;
toggleVisibilityOfElementsInArray(actualCourseGroundLines);
});
$(".toggleTargetCourse").on("click", function() {
targetCourse.show = !targetCourse.show;
});
var result = "DESCENT STATISTICS: \n\n" + buildDataTitles(data);
$(".results").text(result);
$(".results").html($(".results").html().replace(/\n/g,'<br>'));
}, landingApproach: function(data, startTime, endTime) {
targetCourse = viewer.entities.add({
name : 'Target Course',
polyline : {
positions : [data.positions[0], data.positions[data.positions.length-1]],
width : 5,
material : Cesium.Color.BLUE
}
});
actualCourse = viewer.entities.add({
name : 'Actual Course',
polyline: {
positions: data.positions,
material: Cesium.Color.RED
}
});
actualCourseGroundLines = drawGroundPath(data.positions, Cesium.Color.RED.withAlpha(0.5));
usedEntites.push(targetCourse);
usedEntites.push(actualCourse);
for (var i = 0; i<actualCourseGroundLines.length; i++) {
usedEntites.push(actualCourseGroundLines[i]);
}
$(".toggleRealCourse").on("click", function() {
actualCourse.show = !actualCourse.show;
toggleVisibilityOfElementsInArray(actualCourseGroundLines);
});
$(".toggleTargetCourse").on("click", function() {
targetCourse.show = !targetCourse.show;
});
var result = "LANDING APPROACH STATISTICS: \n\n" + buildDataTitles(data);
$(".results").text(result);
$(".results").html($(".results").html().replace(/\n/g,'<br>'));
}, turnsAroundAPoint: function(data, startTime, endTime) {
var totalDistance = 0.0;
for (var i = 0; i < data.positions.length; i++) {
totalDistance += Cesium.Cartesian3.distance(data.averagePosition, data.positions[i]);
}
var averageDistance = totalDistance/data.positions.length;
var targetCourse = viewer.entities.add({
position: data.averagePosition,
name: 'Target Course',
ellipse: {
semiMinorAxis : averageDistance,
semiMajorAxis : averageDistance,
material : Cesium.Color.BLUE.withAlpha(0.5),
outline : true
}
});
var actualCourse = viewer.entities.add({
name: 'Actual Course',
polygon: {
hierarchy: data.positions,
material: Cesium.Color.RED.withAlpha(0.5),
}
});
actualCourseGroundLines = drawGroundPath(data.positions, Cesium.Color.RED.withAlpha(0.5));
usedEntites.push(targetCourse);
usedEntites.push(actualCourse);
for (var i = 0; i<actualCourseGroundLines.length; i++) {
usedEntites.push(actualCourseGroundLines[i]);
}
$(".toggleRealCourse").on("click", function() {
actualCourse.show = !actualCourse.show;
toggleVisibilityOfElementsInArray(actualCourseGroundLines);
});
$(".toggleTargetCourse").on("click", function() {
targetCourse.show = !targetCourse.show;
});
var result = "TURNS AROUND A POINT STATISTICS: \n\n" + buildDataTitles(data);
$(".results").text(result);
$(".results").html($(".results").html().replace(/\n/g,'<br>'));
}
}
data = [];
// Setup Initial KML LOAD
$(".kmlFile").change(function() {
// Set the data source
// $(".kmlFile") is a jquery array, so we need to get the first element (the input), and then query the uploaded files.
// Files[0] is the correct file
var dataSource = Cesium.KmlDataSource.load($(".kmlFile").get(0).files[0],
{
// Set the camera and canvas to the current scene
camera: viewer.scene.camera,
canvas: viewer.scene.canvas
});
$(".fileMessage").text("File Selected: " + $(".kmlFile").get(0).files[0].name);
viewer.dataSources.add(dataSource).then(function(dSource) {
if (dSource._entityCollection._entities._array.length == 2) {
// Foreflight
flight = dSource._entityCollection._entities._array[0];
} else {
// flightaware
flight = dSource._entityCollection._entities._array[dSource._entityCollection._entities._array.length-1];
}
var aboveFlightPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(flight.position.getValue(entity.currentTime));
aboveFlightPosition.height += 10000;
aboveFlightPosition = Cesium.Ellipsoid.WGS84.cartographicToCartesian(aboveFlightPosition);
viewer.camera.flyTo({
destination : aboveFlightPosition
});
});
});
function getPositionData(entity, startTime, endTime) { // Dont use global startTime and endTime
var entityPosition = entity.position;
var data = {
positions: [],
distance: 0
};
var time = Cesium.JulianDate.clone(startTime);
var dayDelta = endTime.dayNumber - startTime.dayNumber;
var secondsDelta = endTime.secondsOfDay - startTime.secondsOfDay;
var delta = dayDelta * NUMBER_OF_SECONDS_IN_DAY + secondsDelta;
var secondsIncrease = delta/NUMBER_OF_POINTS;
var x_total = 0;
var y_total = 0;
var z_total = 0;
var speedTotal = 0;
var altitudeTotal = 0;
var verticalSpeedTotal = 0;
var maxSpeed = -1;
var minSpeed = Number.MAX_VALUE;
var maxAlt = -Number.MAX_VALUE;
var minAlt = Number.MAX_VALUE;
var maxVerticalSpeed = -Number.MAX_VALUE;
var minVerticalSpeed = Number.MAX_VALUE;
var i = 0;
var lastTime;
while (endTime.dayNumber > time.dayNumber || endTime.secondsOfDay >= time.secondsOfDay) { // Cesium.Compare() doesn't work as intended, using custom evaluation
var currentPosition = entityPosition.getValue(time);
data.positions.push(currentPosition);
var cartoPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(currentPosition);
x_total += currentPosition.x;
y_total += currentPosition.y;
z_total += currentPosition.z;
var alt = cartoPosition.height * METERS_TO_FEET;
altitudeTotal += alt;
if (minAlt > alt) {
minAlt = alt;
}
if (maxAlt < alt) {
maxAlt = alt;
}
time.secondsOfDay += secondsIncrease;
if (time.secondsOfDay > NUMBER_OF_SECONDS_IN_DAY) {
time.dayNumber += 1;
time.secondsOfDay -= NUMBER_OF_SECONDS_IN_DAY;
}
if (i > 0) {
var lastPosition = data.positions[i-1];
var legDistance = Math.abs(Cesium.Cartesian3.distance(lastPosition, currentPosition) * METERS_TO_NM)
var heightDistance = METERS_TO_FEET * (cartoPosition.height - Cesium.Ellipsoid.WGS84.cartesianToCartographic(lastPosition).height);
var hoursTimeDifference = SECONDS_TO_HOURS * Math.abs(Cesium.JulianDate.secondsDifference(lastTime, time));
var speed = legDistance/hoursTimeDifference;
var verticalSpeed = heightDistance/(HOURS_TO_MINUTES * hoursTimeDifference);
speedTotal += speed;
verticalSpeedTotal += verticalSpeed;
if (speed > maxSpeed) {
maxSpeed = speed;
}
if (speed < minSpeed) {
minSpeed = speed
}
if (verticalSpeed > maxVerticalSpeed) {
maxVerticalSpeed = verticalSpeed;
}
if (verticalSpeed < minVerticalSpeed) {
minVerticalSpeed = verticalSpeed;
}
data.distance += legDistance;
if (i == 1) {
data.initialSpeed = speed
data.initialVerticalSpeed = verticalSpeed;
} else {
data.finalSpeed = speed
data.finalVerticalSpeed = verticalSpeed;
}
}
lastTime = time.clone();
i++;
}
data.averagePosition = new Cesium.Cartesian3(x_total/data.positions.length, y_total/data.positions.length, z_total/data.positions.length);
data.initialAltitude = Cesium.Ellipsoid.WGS84.cartesianToCartographic(data.positions[0]).height * METERS_TO_FEET
data.finalAltitude = Cesium.Ellipsoid.WGS84.cartesianToCartographic(data.positions[data.positions.length - 1]).height * METERS_TO_FEET
data.maxSpeed = maxSpeed;
data.minSpeed = minSpeed;
data.maxAlt = maxAlt;
data.minAlt = minAlt;
data.averageSpeed = speedTotal/(data.positions.length-1);
data.averageAltitude = altitudeTotal/(data.positions.length-1);
data.minVerticalSpeed = minVerticalSpeed;
data.maxVerticalSpeed = maxVerticalSpeed;
data.averageVerticalSpeed = verticalSpeedTotal/(data.positions.length-1);
return data;
}
$(".toggleFlightPath").on("click", function() {
flight.show = !flight.show;
})
$(".setStartTime").on("click", function() {
StartTime = viewer.clock.currentTime;
$(".setStartTime").hide();
$(".setEndTime").show();
});
$(".setEndTime").on("click", function() {
EndTime = viewer.clock.currentTime;
$(".setStartTime").show();
$(".setEndTime").hide();
});
$(".setManeuver").on("click", function() {
if (StartTime.dayNumber > EndTime.dayNumber && StartTime.EndTime.secondsOfDay > EndTime.secondsOfDay) {
alert("Please Re-Select the Start Selection and End Selection. End of Selection Occurs Before Start of Selection.")
}
for (var i = usedEntites.length-1; i>=0; i--) {
viewer.entities.remove(usedEntites[i]);
usedEntites.splice(i,1);
}
$(".toggleFlightPath").show();
$(".toggleRealCourse").show();
$(".toggleTargetCourse").show();
$(".resultsdiv").show();
data = getPositionData(flight, StartTime, EndTime);
var maneuver = maneuvers[$(".selectmaneuver").val()];
maneuver(data, StartTime, EndTime);
});
});