2016-07-22 14:23:16 +00:00
|
|
|
var lastInputBox;
|
|
|
|
|
2016-07-12 19:52:58 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
// Controls menu hide/show
|
|
|
|
$('#hotdog').click(function(){
|
|
|
|
$('#controls').toggleClass("active");
|
2016-07-22 14:23:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Reset view
|
|
|
|
$('.reset-container').click(function(){ reset_view(); });
|
|
|
|
$('#submitfindbyname').click(function() {
|
2016-07-12 19:52:58 +00:00
|
|
|
var selected = $('#findbyselect option:selected').text();
|
|
|
|
zoomfocus(selected);
|
|
|
|
});
|
2016-07-27 19:43:30 +00:00
|
|
|
$('#route_output').change(function() {
|
|
|
|
var stop=$('#route_output :selected').parent().attr('label');
|
|
|
|
zoomfocus(stop);
|
|
|
|
});
|
2016-07-22 14:23:16 +00:00
|
|
|
$('#calctnd').click(function() {
|
2016-07-27 19:43:30 +00:00
|
|
|
|
2016-07-25 16:03:08 +00:00
|
|
|
removeEntity('arrow');
|
|
|
|
lastInputBox = null;
|
2016-07-27 19:43:30 +00:00
|
|
|
var speed = {'speed': $('#speed').val(), 'unit':$ ('#speedunit option:selected').val() };
|
|
|
|
populateRoutePlan( $('#pointa option:selected').text() , $('#pointb option:selected').text(),speed );
|
|
|
|
|
|
|
|
|
2016-07-22 14:23:16 +00:00
|
|
|
});
|
2016-07-25 16:52:06 +00:00
|
|
|
$('#cbs').click(function() {populateFBSelect(); });
|
|
|
|
$('#cbp').click(function() {populateFBSelect(); });
|
2016-07-22 14:23:16 +00:00
|
|
|
$("#pointa").focus(function() {
|
|
|
|
lastInputBox = "pointa";
|
|
|
|
// console.log('Updating last touched box to : ' + lastInputBox)
|
|
|
|
});
|
|
|
|
$("#pointb").focus(function() {
|
|
|
|
lastInputBox = "pointb";
|
|
|
|
// console.log('Updating last touched box to : ' + lastInputBox)
|
|
|
|
});
|
2016-07-22 19:22:16 +00:00
|
|
|
String.prototype.capitalize = function(lower) {
|
|
|
|
return (lower ? this.toLowerCase() : this).replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
|
|
|
|
};
|
2016-07-22 14:23:16 +00:00
|
|
|
|
|
|
|
|
2016-07-12 19:52:58 +00:00
|
|
|
});
|
|
|
|
|
2016-07-22 14:23:16 +00:00
|
|
|
|
2016-07-12 19:52:58 +00:00
|
|
|
function populateUserFields() {
|
2016-07-25 16:52:06 +00:00
|
|
|
// Populate findby box
|
|
|
|
populateFBSelect();
|
2016-07-22 14:23:16 +00:00
|
|
|
// Populate pointa and pointb dropdowns
|
|
|
|
var types = ['planets','stations'];
|
2016-07-22 19:22:16 +00:00
|
|
|
option = "";
|
2016-07-22 14:23:16 +00:00
|
|
|
for (var type in types){
|
2016-07-22 19:22:16 +00:00
|
|
|
var keys = Object.keys(listobjects(types[type]));
|
|
|
|
var captype = types[type];
|
|
|
|
captype = captype.capitalize()
|
2016-07-27 19:43:30 +00:00
|
|
|
option += '<optgroup label="'+ captype + '">';
|
2016-07-22 19:22:16 +00:00
|
|
|
keys.sort().forEach(function(element, index, array){
|
|
|
|
option += '<option value="'+ escapeHTML(element) + '">' + escapeHTML(element) + '</option>';
|
|
|
|
});
|
2016-07-27 19:43:30 +00:00
|
|
|
option += '</optgroup>';
|
2016-07-22 19:22:16 +00:00
|
|
|
|
2016-07-22 14:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$('#pointa').html(option);
|
|
|
|
$('#pointb').html(option);
|
|
|
|
|
2016-07-25 16:52:06 +00:00
|
|
|
}
|
|
|
|
function populateFBSelect() {
|
|
|
|
//Populate find by select dropdown
|
|
|
|
var types = [];
|
|
|
|
var checkboxes = document.getElementsByName("objtype");
|
|
|
|
for (var type in checkboxes) {
|
|
|
|
if(checkboxes[type].checked) {
|
|
|
|
types[type] = checkboxes[type].value;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
var option = '';
|
|
|
|
for (var type in types) {
|
2016-07-27 19:43:30 +00:00
|
|
|
var captype = types[type];
|
|
|
|
captype = captype.capitalize()
|
|
|
|
option += '<optgroup label="'+ captype + '">';
|
2016-07-25 16:52:06 +00:00
|
|
|
var keys = Object.keys(listobjects(types[type]));
|
|
|
|
keys.sort().forEach(function(element, index, array){
|
|
|
|
option += '<option value="'+ escapeHTML(element) + '">' + escapeHTML(element) + '</option>';
|
|
|
|
});
|
2016-07-27 19:43:30 +00:00
|
|
|
option += '</optgroup>';
|
2016-07-25 16:52:06 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#findbyselect').html(option);
|
|
|
|
|
2016-07-12 19:52:58 +00:00
|
|
|
}
|
2016-07-08 19:18:12 +00:00
|
|
|
|
|
|
|
function openTab(evt,tabName) {
|
|
|
|
var i, x, tablinks;
|
2016-07-12 19:52:58 +00:00
|
|
|
x = document.getElementsByClassName("wvg-tools");
|
2016-07-08 19:07:21 +00:00
|
|
|
for (i = 0; i < x.length; i++) {
|
2016-07-08 19:18:12 +00:00
|
|
|
x[i].style.display = "none";
|
2016-07-08 19:07:21 +00:00
|
|
|
}
|
2016-07-12 19:52:58 +00:00
|
|
|
tablinks = document.getElementsByClassName("wvg-tablink");
|
2016-07-08 19:18:12 +00:00
|
|
|
for (i = 0; i < x.length; i++) {
|
2016-07-12 19:52:58 +00:00
|
|
|
tablinks[i].className = tablinks[i].className.replace(" wvg-tab-active", "");
|
2016-07-08 19:18:12 +00:00
|
|
|
}
|
|
|
|
document.getElementById(tabName).style.display = "block";
|
2016-07-12 19:52:58 +00:00
|
|
|
evt.currentTarget.className += " wvg-tab-active";
|
2016-07-08 19:07:21 +00:00
|
|
|
}
|
2016-07-12 19:52:58 +00:00
|
|
|
|
2016-07-22 14:23:16 +00:00
|
|
|
function escapeHTML(text) {
|
2016-07-12 19:52:58 +00:00
|
|
|
var chr = { '"': '"', '&': '&', '<': '[', '>': ']' };
|
|
|
|
function abc(a)
|
|
|
|
{
|
|
|
|
return chr[a];
|
|
|
|
}
|
|
|
|
return text.replace(/[\"&<>]/g, abc);
|
2016-07-22 14:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function timeformat(secs) {
|
|
|
|
var s = new Decimal(secs);
|
|
|
|
var hours = new Decimal(secs / 3600);
|
|
|
|
var h = hours.floor(); //Get whole hours
|
|
|
|
s = s - (h * 3600);
|
|
|
|
var m = new Decimal(s / 60); //Get remaining minutes
|
|
|
|
m = m.floor();
|
|
|
|
s = s - (m * 60 );
|
|
|
|
s = Math.round(s,0)
|
2016-07-22 15:49:31 +00:00
|
|
|
// console.log("Hours :"+ h);
|
|
|
|
// console.log("Minutes :"+ m);
|
|
|
|
// console.log("Seconds :"+ s);
|
|
|
|
// console.log("Input :"+ secs);
|
2016-07-22 14:23:16 +00:00
|
|
|
return h+":"+(m < 10 ? '0'+m : m)+":"+(s < 10 ? '0'+s : s); //zero padding on minutes and seconds
|
|
|
|
}
|
2016-07-27 19:43:30 +00:00
|
|
|
|
|
|
|
function populateRoutePlan(pointa,pointb,speed) {
|
|
|
|
if ( pointa != pointb ) {
|
|
|
|
// Populate legacy (trip total) fields with route info
|
|
|
|
$('#cal_start').html( pointa );
|
|
|
|
$('#cal_end').html( pointb );
|
|
|
|
$('#cal_speed').html( speed.speed + " " + speed.unit );
|
|
|
|
var route = calcBestRoute(pointa,pointb);
|
|
|
|
console.log(route)
|
|
|
|
var dist = route.distance;
|
|
|
|
var eta = calcETA(speed,dist);
|
|
|
|
$('#cal_eta').html( timeformat(eta) );
|
|
|
|
$('#cal_dist').html( dist.toFixed(2) + " PC");
|
|
|
|
|
|
|
|
// Populate the route plan select area
|
|
|
|
lastWaypoint = {'name': pointa, gate:false};
|
|
|
|
var routeplan;
|
|
|
|
route.stops.forEach(function(waypoint,index,self) {
|
|
|
|
routeplan += '<optgroup label="' + waypoint.name + '">';
|
|
|
|
if(typeof self[index+1] != 'undefined' ) {
|
|
|
|
if(waypoint.gate && self[index+1].gate) {routeplan += '<option>^---- Gate From</option>'; }
|
|
|
|
console.log(waypoint.gate)
|
|
|
|
}
|
|
|
|
if(waypoint.gate && lastWaypoint.gate) {routeplan += '<option>^---- Gate Exit</option>'; }
|
|
|
|
|
|
|
|
if(!waypoint.gate || (!lastWaypoint.gate && waypoint.gate)) {
|
|
|
|
routeplan += '<option>Distance:' + calcDist(lastWaypoint.name,waypoint.name) + '</option>'
|
|
|
|
routeplan += '<option>ETA: ' + timeformat(calcETA(speed,calcDist(lastWaypoint.name,waypoint.name))) + '</option>';
|
|
|
|
drawline(grabPositionByName(lastWaypoint.name),grabPositionByName(waypoint.name));
|
|
|
|
}
|
|
|
|
lastWaypoint = waypoint;
|
|
|
|
});
|
|
|
|
$('#route_output').html(routeplan);
|
|
|
|
//drawline(grabPositionByName($('#pointa option:selected').text()),grabPositionByName($('#pointb option:selected').text()));
|
|
|
|
}
|
|
|
|
}
|