Convert bearing lookup to POST request

This commit is contained in:
phl0 2023-08-25 16:26:25 +02:00
parent 522854377b
commit 3efcbf0b0d
No known key found for this signature in database
GPG Key ID: 48EA1E640798CA9A
3 changed files with 31 additions and 5 deletions

View File

@ -878,7 +878,9 @@ class Logbook extends CI_Controller {
/* return station bearing */
function searchbearing($locator, $station_id = null) {
function searchbearing() {
$locator = xss_clean($this->input->post('grid'));
$station_id = xss_clean($this->input->post('stationProfile'));
$this->load->library('Qra');
if($locator != null) {

View File

@ -26,9 +26,12 @@ class Qra {
$my = qra2latlong($tx);
$stn = qra2latlong($rx);
if ($my !== false && $stn !== false ) {
$bearing = bearing($my[0], $my[1], $stn[0], $stn[1], $unit);
return $bearing;
} else {
return false;
}
}
/*
@ -168,6 +171,11 @@ function qra2latlong($strQRA) {
if (substr_count($strQRA, ',') == 3) {
// Handle grid corners
$grids = explode(',', $strQRA);
$gridlengths = array(strlen($grids[0]), strlen($grids[1]), strlen($grids[2]), strlen($grids[3]));
$same = array_count_values($gridlengths);
if (count($same) != 1) {
return false;
}
$coords = array(0, 0);
for($i=0; $i<4; $i++) {
$cornercoords[$i] = qra2latlong($grids[$i]);
@ -178,6 +186,9 @@ function qra2latlong($strQRA) {
} else if (substr_count($strQRA, ',') == 1) {
// Handle grid lines
$grids = explode(',', $strQRA);
if (strlen($grids[0]) != strlen($grids[1])) {
return false;
}
$coords = array(0, 0);
for($i=0; $i<2; $i++) {
$linecoords[$i] = qra2latlong($grids[$i]);

View File

@ -829,7 +829,20 @@ $("#locator").keyup(function(){
markers.addLayer(marker).addTo(mymap);
})
$('#locator_info').load(base_url +"index.php/logbook/searchbearing/" + $(this).val() + "/" + $('#stationProfile').val()).fadeIn("slow");
$.ajax({
url: base_url + 'index.php/logbook/searchbearing',
type: 'post',
data: {
grid: $(this).val(),
stationProfile: $('#stationProfile').val()
},
success: function(data) {
$('#locator_info').html(data).fadeIn("slow");
},
error: function() {
$('#locator_info').text("Error loading bearing and distance").fadeIn("slow");
},
});
$.get(base_url + 'index.php/logbook/searchdistance/' + $(this).val() + "/" + $('#stationProfile').val(), function(result) {
document.getElementById("distance").value = result;
});