[QRB Calc] Added some error checking and rounding of coordinates.
这个提交包含在:
父节点
831708ffc2
当前提交
0763e64777
共有 2 个文件被更改,包括 41 次插入 和 20 次删除
|
|
@ -18,7 +18,7 @@ class Qrbcalc extends CI_Controller {
|
||||||
|
|
||||||
$this->load->model('stations');
|
$this->load->model('stations');
|
||||||
$data['station_locator'] = $this->stations->find_gridsquare();
|
$data['station_locator'] = $this->stations->find_gridsquare();
|
||||||
|
|
||||||
$this->load->view('qrbcalc/index', $data);
|
$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['result'] = $this->qra->bearing($locator1, $locator2, $measurement_base);
|
||||||
$data['distance'] = $this->qra->distance($locator1, $locator2, $measurement_base) . $var_dist;
|
$data['distance'] = $this->qra->distance($locator1, $locator2, $measurement_base) . $var_dist;
|
||||||
$data['bearing'] = $this->qra->get_bearing($locator1, $locator2) . "º ";
|
$data['bearing'] = $this->qra->get_bearing($locator1, $locator2) . "º ";
|
||||||
$data['latlng1'] = $this->qra->qra2latlong($locator1);
|
$latlng1 = $this->qra->qra2latlong($locator1);
|
||||||
$data['latlng2'] = $this->qra->qra2latlong($locator2);
|
$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');
|
header('Content-Type: application/json');
|
||||||
echo json_encode($data);
|
echo json_encode($data);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -457,23 +457,37 @@ function calculateQrb(form) {
|
||||||
let locator1 = form.locator1.value;
|
let locator1 = form.locator1.value;
|
||||||
let locator2 = form.locator2.value;
|
let locator2 = form.locator2.value;
|
||||||
|
|
||||||
$.ajax({
|
$(".qrbalert").remove();
|
||||||
url: base_url+'index.php/qrbcalc/calculate',
|
|
||||||
type: 'post',
|
if (validateLocator(locator1) && validateLocator(locator2)) {
|
||||||
data: {'locator1': locator1,
|
$.ajax({
|
||||||
'locator2': locator2},
|
url: base_url+'index.php/qrbcalc/calculate',
|
||||||
success: function (html) {
|
type: 'post',
|
||||||
|
data: {'locator1': locator1,
|
||||||
var result = "<h5>Negative latitudes are south of the equator, negative longitudes are west of Greenwich. <br/>";
|
'locator2': locator2},
|
||||||
result += ' ' + locator1.toUpperCase() + ' Latitude = ' + html['latlng1'][0] + ' Longitude = ' + html['latlng1'][1] + '<br/>';
|
success: function (html) {
|
||||||
result += ' ' + locator2.toUpperCase() + ' Latitude = ' + html['latlng2'][0] + ' Longitude = ' + html['latlng2'][1] + '<br/>';
|
|
||||||
result += 'Distance between ' + locator1.toUpperCase() + ' and ' + locator2.toUpperCase() + ' is ' + html['distance'] + '. and ';
|
var result = "<h5>Negative latitudes are south of the equator, negative longitudes are west of Greenwich. <br/>";
|
||||||
result += 'the bearing is ' + html['bearing'] + '.</h5>';
|
result += ' ' + locator1.toUpperCase() + ' Latitude = ' + html['latlng1'][0] + ' Longitude = ' + html['latlng1'][1] + '<br/>';
|
||||||
|
result += ' ' + locator2.toUpperCase() + ' Latitude = ' + html['latlng2'][0] + ' Longitude = ' + html['latlng2'][1] + '<br/>';
|
||||||
$(".qrbResult").html(result);
|
result += 'Distance between ' + locator1.toUpperCase() + ' and ' + locator2.toUpperCase() + ' is ' + html['distance'] + '. and ';
|
||||||
newpath(html['latlng1'], html['latlng2']);
|
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) {
|
function newpath(locator1, locator2) {
|
||||||
|
|
|
||||||
正在加载…
在新工单中引用