Skip to content

Commit b74896b

Browse files
authored
Make coordinates clickable everywhere (projecthorus#338)
1 parent c96385b commit b74896b

File tree

3 files changed

+26
-42
lines changed

3 files changed

+26
-42
lines changed

js/app.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,25 @@ var format_time_friendly = function(start, end) {
445445
}
446446
};
447447

448+
var format_coordinates = function(lat, lon, name) {
449+
var coords_text;
450+
var ua = navigator.userAgent.toLowerCase();
451+
452+
// determine how to link the coordinates to a native app, if on a mobile device
453+
if(ua.indexOf('iphone') > -1) {
454+
coords_text = '<a href="maps://?q='+lat+','+lon+'">' +
455+
roundNumber(lat, 5) + ', ' + roundNumber(lon, 5) +'</a>';
456+
} else if(ua.indexOf('android') > -1) {
457+
coords_text = '<a href="geo:'+lat+','+lon+'?q='+lat+','+lon+'('+name+')">' +
458+
roundNumber(lat, 5) + ', ' + roundNumber(lon, 5) +'</a>';
459+
} else {
460+
coords_text = '<a href="https://www.google.com/maps/search/?api=1&query='+lat+','+lon+'" target="_blank" rel="noopener noreferrer">' +
461+
roundNumber(lat, 5) + ', ' + roundNumber(lon, 5) +'</a>';
462+
}
463+
464+
return coords_text;
465+
};
466+
448467
// runs every second
449468
var updateTime = function(date) {
450469
// update timebox
@@ -553,12 +572,6 @@ $(window).ready(function() {
553572
$("#main").removeClass("drag");
554573
});
555574

556-
// confirm dialog when launchnig a native map app with coordinates
557-
//$('#main').on('click', '#launch_mapapp', function() {
558-
// var answer = confirm("Launch your maps app?");
559-
// return answer;
560-
//});
561-
562575
// follow vehicle by clicking on data
563576
$('#main').on('click', '.row .data', function() {
564577
var e = $(this).parent();

js/station.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ function drawHistorical (data, station) {
179179
html = "<div style='line-height:16px;position:relative;'>";
180180
html += "<div>"+serial+" <span style=''>("+time+")</span></div>";
181181
html += "<hr style='margin:5px 0px'>";
182-
html += "<div><b>Last Position:&nbsp;</b>"+roundNumber(landing.lat, 5) + ',&nbsp;' + roundNumber(landing.lon, 5)+"</div>";
182+
html += "<div><b>Last Position:&nbsp;</b>"+format_coordinates(landing.lat, landing.lon, serial)+"</div>";
183183

184184
var imp = offline.get('opt_imperial');
185185
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(landing.alt)) : parseInt(landing.alt)).toLocaleString("us");

js/tracker.js

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,23 +1799,7 @@ function updateVehicleInfo(vcallsign, newPosition) {
17991799
hrate_text = imp ? (vehicle.horizontal_rate * 196.850394).toFixed(1) + ' ft/min' : vehicle.horizontal_rate.toFixed(1) + ' m/s';
18001800
}
18011801

1802-
var coords_text;
1803-
var ua = navigator.userAgent.toLowerCase();
1804-
1805-
// determine how to link the vehicle coordinates to a native app, if on a mobile device
1806-
if(ua.indexOf('iphone') > -1) {
1807-
coords_text = '<a id="launch_mapapp" href="maps://?q='+newPosition.gps_lat+','+newPosition.gps_lon+'">' +
1808-
roundNumber(newPosition.gps_lat, 5) + ', ' + roundNumber(newPosition.gps_lon, 5) +'</a>' +
1809-
' <i class="icon-location"></i>';
1810-
} else if(ua.indexOf('android') > -1) {
1811-
coords_text = '<a id="launch_mapapp" href="geo:'+newPosition.gps_lat+','+newPosition.gps_lon+'?q='+newPosition.gps_lat+','+newPosition.gps_lon+'('+vcallsign+')">' +
1812-
roundNumber(newPosition.gps_lat, 5) + ', ' + roundNumber(newPosition.gps_lon, 5) +'</a>' +
1813-
' <i class="icon-location"></i>';
1814-
} else {
1815-
coords_text = '<a id="launch_mapapp" href="https://www.google.com/maps/search/?api=1&query='+newPosition.gps_lat+','+newPosition.gps_lon+'" target="_blank" rel="noopener noreferrer">' +
1816-
roundNumber(newPosition.gps_lat, 5) + ', ' + roundNumber(newPosition.gps_lon, 5) +'</a>' +
1817-
' <i class="icon-location"></i>';
1818-
}
1802+
var coords_text = format_coordinates(newPosition.gps_lat, newPosition.gps_lon, vcallsign) + ' <i class="icon-location"></i>';
18191803

18201804
// format altitude strings
18211805
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(newPosition.gps_alt)) : parseInt(newPosition.gps_alt)).toLocaleString("us");
@@ -2722,7 +2706,7 @@ function mapInfoBox_handle_path_old(vehicle, id) {
27222706
html = "<div style='line-height:16px;position:relative;'>";
27232707
html += "<div>"+data.serial+" <span style=''>("+data.datetime+")</span></div>";
27242708
html += "<hr style='margin:5px 0px'>";
2725-
html += "<div style='margin-bottom:5px;'><b><i class='icon-location'></i>&nbsp;</b>"+roundNumber(data.lat, 5) + ',&nbsp;' + roundNumber(data.lon, 5)+"</div>";
2709+
html += "<div style='margin-bottom:5px;'><b><i class='icon-location'></i>&nbsp;</b>"+format_coordinates(data.lat, data.lon, data.serial)+"</div>";
27262710

27272711
var imp = offline.get('opt_imperial');
27282712
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(data.alt)) : parseInt(data.alt)).toLocaleString("us");
@@ -2797,7 +2781,7 @@ function mapInfoBox_handle_path_new(data, vehicle, date) {
27972781
html = "<div style='line-height:16px;position:relative;'>";
27982782
html += "<div>"+data.serial+" <span style=''>("+date+")</span></div>";
27992783
html += "<hr style='margin:5px 0px'>";
2800-
html += "<div style='margin-bottom:5px;'><b><i class='icon-location'></i>&nbsp;</b>"+roundNumber(data.lat, 5) + ',&nbsp;' + roundNumber(data.lon, 5)+"</div>";
2784+
html += "<div style='margin-bottom:5px;'><b><i class='icon-location'></i>&nbsp;</b>"+format_coordinates(data.lat, data.lon, data.serial)+"</div>";
28012785

28022786
var imp = offline.get('opt_imperial');
28032787
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(data.alt)) : parseInt(data.alt)).toLocaleString("us");
@@ -2931,20 +2915,7 @@ function mapInfoBox_handle_prediction(event) {
29312915
altitude = Math.round(data.alt) + " m";
29322916
}
29332917

2934-
var coords_text;
2935-
var ua = navigator.userAgent.toLowerCase();
2936-
2937-
// determine how to link the vehicle coordinates to a native app, if on a mobile device
2938-
if(ua.indexOf('iphone') > -1) {
2939-
coords_text = '<a href="maps://?q='+data.lat+','+data.lon+'">' +
2940-
roundNumber(data.lat, 5) + ', ' + roundNumber(data.lon, 5) + '</a>';
2941-
} else if(ua.indexOf('android') > -1) {
2942-
coords_text = '<a href="geo:'+data.lat+','+data.lon+'?q='+data.lat+','+data.lon+'(Prediction)">' +
2943-
roundNumber(data.lat, 5) + ', ' + roundNumber(data.lon, 5) +'</a>';
2944-
} else {
2945-
coords_text = '<a href="https://www.google.com/maps/search/?api=1&query='+data.lat+','+data.lon+'" target="_blank" rel="noopener noreferrer">' +
2946-
roundNumber(data.lat, 5) + ', ' + roundNumber(data.lon, 5) +'</a>';
2947-
}
2918+
var coords_text = format_coordinates(data.lat, data.lon, "Prediction");
29482919

29492920
mapInfoBox.setContent("<pre>" +
29502921
formatDate(new Date(parseInt(data.time) * 1000), true) + "\n\n" +
@@ -4665,7 +4636,7 @@ function updateRecoveryMarker(recovery) {
46654636
html = "<div style='line-height:16px;position:relative;'>";
46664637
html += "<div><b>"+recovery.serial+(recovery.recovered ? " Recovered" : " Not Recovered")+"</b></div>";
46674638
html += "<hr style='margin:5px 0px'>";
4668-
html += "<div style='margin-bottom:5px;'><b><i class='icon-location'></i>&nbsp;</b>"+roundNumber(recovery.lat, 5) + ',&nbsp;' + roundNumber(recovery.lon, 5)+"</div>";
4639+
html += "<div style='margin-bottom:5px;'><b><i class='icon-location'></i>&nbsp;</b>"+format_coordinates(recovery.lat, recovery.lon, recovery.serial)+"</div>";
46694640

46704641
var imp = offline.get('opt_imperial');
46714642
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(recovery.alt)) : parseInt(recovery.alt)).toLocaleString("us");
@@ -4777,7 +4748,7 @@ function updateRecoveryPane(r){
47774748

47784749
html += "<div style='line-height:16px;position:relative;'>";
47794750
html += "<div><b><u>"+r[i].serial+(r[i].recovered ? " Recovered by " : " Not Recovered by ")+r[i].recovered_by+"</u></b></div>";
4780-
html += "<div style='margin-bottom:5px;'><b><button style='margin-bottom:0px;' onclick='panToRecovery(\"" + r[i].serial + "\")'><i class='icon-location'></i></button>&nbsp;</b>"+roundNumber(lat, 5) + ',&nbsp;' + roundNumber(lon, 5)+"</div>";
4751+
html += "<div style='margin-bottom:5px;'><b><button style='margin-bottom:0px;' onclick='panToRecovery(\"" + r[i].serial + "\")'><i class='icon-location'></i></button>&nbsp;</b>"+format_coordinates(lat, lon, r[i].serial)+"</div>";
47814752

47824753
var imp = offline.get('opt_imperial');
47834754
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(alt)) : parseInt(alt)).toLocaleString("us");

0 commit comments

Comments
 (0)