From 77a26bf1f61ce9e0709429c79f99ab2641d7f996 Mon Sep 17 00:00:00 2001 From: Rob L Date: Wed, 27 Jul 2016 15:43:30 -0400 Subject: [PATCH] Add route planner --- js/GUI.Utils.js | 62 ++++++++++++++++++++++++++++++++++++++++--------- js/mapviewgl.js | 23 +++++++++--------- webviewgl.htm | 27 ++++++++++++++------- 3 files changed, 82 insertions(+), 30 deletions(-) diff --git a/js/GUI.Utils.js b/js/GUI.Utils.js index 168a8ec..9d1fa90 100644 --- a/js/GUI.Utils.js +++ b/js/GUI.Utils.js @@ -12,19 +12,18 @@ $(document).ready(function() { var selected = $('#findbyselect option:selected').text(); zoomfocus(selected); }); + $('#route_output').change(function() { + var stop=$('#route_output :selected').parent().attr('label'); + zoomfocus(stop); + }); $('#calctnd').click(function() { + removeEntity('arrow'); lastInputBox = null; - if ( $('#pointa option:selected').text() != $('#pointb option:selected').text() && (!$('#pointa option:selected').text().match("[=.] (.+) [=.]") && !$('#pointb option:selected').text().match("[=.] (.+) [=.]"))) { - $('#cal_start').html( $('#pointa option:selected').text() ); - $('#cal_end').html( $('#pointb option:selected').text() ); - $('#cal_speed').html( $('#speed').val() +" " + $('#speedunit option:selected').val() ); - var dist = calcDist( $('#pointa option:selected').text(), $('#pointb option:selected').text() ); - var eta = calcETA({'speed': $('#speed').val(), 'unit': $('#speedunit option:selected').val()},dist) - $('#cal_eta').html( timeformat(eta) ); - $('#cal_dist').html( dist.toFixed(2) + " PC"); - drawline(grabPositionByName($('#pointa option:selected').text()),grabPositionByName($('#pointb option:selected').text())); - } + var speed = {'speed': $('#speed').val(), 'unit':$ ('#speedunit option:selected').val() }; + populateRoutePlan( $('#pointa option:selected').text() , $('#pointb option:selected').text(),speed ); + + }); $('#cbs').click(function() {populateFBSelect(); }); $('#cbp').click(function() {populateFBSelect(); }); @@ -54,10 +53,11 @@ function populateUserFields() { var keys = Object.keys(listobjects(types[type])); var captype = types[type]; captype = captype.capitalize() - option += ''; + option += ''; keys.sort().forEach(function(element, index, array){ option += ''; }); + option += ''; } @@ -77,10 +77,14 @@ function populateFBSelect() { } var option = ''; for (var type in types) { + var captype = types[type]; + captype = captype.capitalize() + option += ''; var keys = Object.keys(listobjects(types[type])); keys.sort().forEach(function(element, index, array){ option += ''; }); + option += ''; } @@ -126,3 +130,39 @@ function timeformat(secs) { // console.log("Input :"+ secs); return h+":"+(m < 10 ? '0'+m : m)+":"+(s < 10 ? '0'+s : s); //zero padding on minutes and seconds } + +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 += ''; + if(typeof self[index+1] != 'undefined' ) { + if(waypoint.gate && self[index+1].gate) {routeplan += ''; } + console.log(waypoint.gate) + } + if(waypoint.gate && lastWaypoint.gate) {routeplan += ''; } + + if(!waypoint.gate || (!lastWaypoint.gate && waypoint.gate)) { + routeplan += '' + routeplan += ''; + drawline(grabPositionByName(lastWaypoint.name),grabPositionByName(waypoint.name)); + } + lastWaypoint = waypoint; + }); + $('#route_output').html(routeplan); + //drawline(grabPositionByName($('#pointa option:selected').text()),grabPositionByName($('#pointb option:selected').text())); + } +} diff --git a/js/mapviewgl.js b/js/mapviewgl.js index 94a1156..3482c17 100644 --- a/js/mapviewgl.js +++ b/js/mapviewgl.js @@ -251,8 +251,11 @@ function drawline(origin,dest) { } function removeEntity(object) { - var selectedObject = scene.getObjectByName(object); + var selectedObject; + while ( selectedObject = scene.getObjectByName(object) ) { scene.remove( selectedObject ); + } + animate(); } @@ -333,19 +336,20 @@ function calcBestRoute(pointa,pointb) { delete route['0']; // WTF? We shouldn't need to do this. I hate JS.... // Calculate direct route. - route['Direct'] = { 'stops': [pointb], 'distance': calcDist(pointa, pointb)}; + route['Direct'] = { 'stops': [{'name':pointb, 'gate': false}], 'distance': calcDist(pointa, pointb)}; // Find route via stargate. var distance_a = {}; var distance_b = {}; var near_a,near_b; // Find gate closest to point a - jsonGate.forEach(function(name) { distance_a[name.name] = calcDist(pointa,name.name) ;}); + jsonGate.forEach(function(name) { distance_a[name.name] = calcDist(pointa,name.name);}); var dist_a_sorted = Object.keys(distance_a).sort(function(a,b) {return distance_a[a]-distance_a[b]}); var near_a = dist_a_sorted[0]; + // Dump out right now if A->nearest gate > direct. Save the compute cycles. - if(distance_a[near_a] > route['Direct'].distance) { + if(distance_a[near_a] > route['Direct'].distance || near_a == pointb) { return route['Direct']; } @@ -355,17 +359,14 @@ function calcBestRoute(pointa,pointb) { var near_b = dist_b_sorted[0]; // Dump out right now if B->nearest gate > direct or the same fucking gate. Save the compute cycles. - - if(distance_a[near_b] > route['Direct'].distance || near_a == near_b) { - return route['Direct']; + if(distance_b[near_b] > route['Direct'].distance || near_a == near_b) { + return route['Direct']; } // Assemble the gate travel plan. With our powers unite, we are shitty code! gate_distance = distance_a[near_a] + distance_b[near_b]; - route['Gate'] = {'stops': [near_a,near_b,pointb], 'distance':gate_distance} + route['Gate'] = {'stops': [{'name':near_a, 'gate':true} ,{'name': near_b, 'gate': true},{'name': pointb, 'gate':false}], 'distance':gate_distance} - // Sort all routes by distance traveled. - - console.log(Object.keys(route)) + // Sort all routes by distance traveled. Index of zero should be the fastest, in theory any way var route_keys_sorted = Object.keys(route).sort(function(a,b) {return route[a].distance-route[b].distance}); return route[route_keys_sorted[0]]; diff --git a/webviewgl.htm b/webviewgl.htm index ab9705b..e2123fa 100644 --- a/webviewgl.htm +++ b/webviewgl.htm @@ -27,10 +27,10 @@ .reset-button {margin: 0; padding: 0; padding: 3px 3px; color: #AAA; } .menu-button { float: right; position: absolute; right: 0.1vw; top: 0; z-index: 5; color:white; background-color:#003133; padding: 0px; font-weight: bold; font-size:2.5vh; } .reset-container { margin: 0; padding: 10px; font-weight: bold; text-align: center; font-family: 'Space Mono', monospace; color:#67989A; background-color: maroon; width: 100%; height: 2.5vh; float:bottom; } - .wvg-controls { position: fixed; left: 85%; height: 96%; width: 15%; margin-top: 0; display: none;} - ul.wvg-navbar { height: 3vh; width: 100%; background-color: #003133; list-style-type: none; overflow: hidden; padding: 0; margin: 0; } - ul.wvg-navbar li { width:auto; height: 100%; float: left; } .wvg-tablink { margin: 0; padding: 0; padding: 8px 10px; font-weight: bold; text-align: center; font-family: 'Space Mono', monospace; color:#67989A; } - .wvg-tab-active { background-color: #0D4A4D; color: #003133; } + .wvg-controls { position: fixed; left: 85%; height: 96%; width: 15%; margin: 0; display: none;} + ul.wvg-navbar { height: 3vh; width: 100%; background-color: #003133; list-style-type: none; overflow: hidden; padding: 0; margin: 0; border: 0; } + ul.wvg-navbar li { width:auto; height: 100%; float: left; padding: 0; margin: 0; border: 0; } .wvg-tablink { height: 100%; border: 0; margin: 0; padding: 0; padding: 8px 10px; font-weight: bold; text-align: center; font-family: 'Space Mono', monospace; color:#67989A; font-size: 1.25vh; } + .wvg-tab-active { background-color: #0D4A4D; color: #003133; } .wvg-tools { width: 100%; height: 98%; background: #333; display: none; color: #AAA; padding-top: 2vh; padding-left:1vw; padding-right: 2.5vw;} .wvg-tools select, .wvg-tools input { width: 12vw; @@ -44,6 +44,7 @@ background: url('assets/select-arrow.png') no-repeat right center #333; color: #67989A; margin: 0 auto; + } .wvg-tools input { background: #333; width: 11.4vw; } .wvg-tools span { text-align: center; color: #FFF; font-family: 'Space Mono', monospace; display: block; padding-right: 3vw; } @@ -102,7 +103,7 @@ text-decoration: none; } .tool-header { font-weight: bold; padding-top: 5vh; display: block; } - + #route_output {font-size: 0.9vh; height: 25%; padding-top: 2.5vh;} .toolsep { margin-right: 1vw; padding:0; padding-top: 1vh; padding-bottom: 2.5vh; border-bottom: 1px #AAA solid; height: 1vh; display: block; width: 64%;} .calc_data { padding-top: 2.5vh; font-size: 0.9em; } @@ -114,8 +115,10 @@
Find Object By Name @@ -127,7 +130,9 @@ - Travel Time & Distances +
+
+ Route Planner + + +
From: Empty
To: Empty
Distance: Unknown
ETA @ Unknown : Unknown
-
+
This tool was designed by Frey @ ATSMUSH. It is based on MapView for ATS with data used from the Navcomp MUSHClient plugin with permission.