[QRB Calc] Added some error checking and rounding of coordinates.

pull/1406/head
Andreas 2022-02-15 22:17:37 +01:00
rodzic 831708ffc2
commit 0763e64777
2 zmienionych plików z 41 dodań i 20 usunięć

Wyświetl plik

@ -18,7 +18,7 @@ class Qrbcalc extends CI_Controller {
$this->load->model('stations');
$data['station_locator'] = $this->stations->find_gridsquare();
$this->load->view('qrbcalc/index', $data);
}
@ -50,8 +50,15 @@ class Qrbcalc extends CI_Controller {
$data['result'] = $this->qra->bearing($locator1, $locator2, $measurement_base);
$data['distance'] = $this->qra->distance($locator1, $locator2, $measurement_base) . $var_dist;
$data['bearing'] = $this->qra->get_bearing($locator1, $locator2) . "º ";
$data['latlng1'] = $this->qra->qra2latlong($locator1);
$data['latlng2'] = $this->qra->qra2latlong($locator2);
$latlng1 = $this->qra->qra2latlong($locator1);
$latlng2 = $this->qra->qra2latlong($locator2);
$latlng1[0] = number_format((float)$latlng1[0], 3, '.', '');;
$latlng1[1] = number_format((float)$latlng1[1], 3, '.', '');;
$latlng2[0] = number_format((float)$latlng2[0], 3, '.', '');;
$latlng2[1] = number_format((float)$latlng2[1], 3, '.', '');;
$data['latlng1'] = $latlng1;
$data['latlng2'] = $latlng2;
header('Content-Type: application/json');
echo json_encode($data);
}

Wyświetl plik

@ -457,23 +457,37 @@ function calculateQrb(form) {
let locator1 = form.locator1.value;
let locator2 = form.locator2.value;
$.ajax({
url: base_url+'index.php/qrbcalc/calculate',
type: 'post',
data: {'locator1': locator1,
'locator2': locator2},
success: function (html) {
var result = "<h5>Negative latitudes are south of the equator, negative longitudes are west of Greenwich. <br/>";
result += ' ' + locator1.toUpperCase() + ' Latitude = ' + html['latlng1'][0] + ' Longitude = ' + html['latlng1'][1] + '<br/>';
result += ' ' + locator2.toUpperCase() + ' Latitude = ' + html['latlng2'][0] + ' Longitude = ' + html['latlng2'][1] + '<br/>';
result += 'Distance between ' + locator1.toUpperCase() + ' and ' + locator2.toUpperCase() + ' is ' + html['distance'] + '. and ';
result += 'the bearing is ' + html['bearing'] + '.</h5>';
$(".qrbResult").html(result);
newpath(html['latlng1'], html['latlng2']);
}
});
$(".qrbalert").remove();
if (validateLocator(locator1) && validateLocator(locator2)) {
$.ajax({
url: base_url+'index.php/qrbcalc/calculate',
type: 'post',
data: {'locator1': locator1,
'locator2': locator2},
success: function (html) {
var result = "<h5>Negative latitudes are south of the equator, negative longitudes are west of Greenwich. <br/>";
result += ' ' + locator1.toUpperCase() + ' Latitude = ' + html['latlng1'][0] + ' Longitude = ' + html['latlng1'][1] + '<br/>';
result += ' ' + locator2.toUpperCase() + ' Latitude = ' + html['latlng2'][0] + ' Longitude = ' + html['latlng2'][1] + '<br/>';
result += 'Distance between ' + locator1.toUpperCase() + ' and ' + locator2.toUpperCase() + ' is ' + html['distance'] + '. and ';
result += 'the bearing is ' + html['bearing'] + '.</h5>';
$(".qrbResult").html(result);
newpath(html['latlng1'], html['latlng2']);
}
});
} else {
$('.qrbResult').html('<div class="qrbalert alert alert-danger" role="alert">Error in locators. Please check.</div>');
}
}
function validateLocator(locator) {
if(locator.length < 4 && !(/^[a-rA-R]{2}[0-9]{2}[a-xA-X]{0,2}[0-9]{0,2}[a-xA-X]{0,2}$/.test(locator))) {
return false;
}
return true;
}
function newpath(locator1, locator2) {