diff --git a/application/controllers/Qrbcalc.php b/application/controllers/Qrbcalc.php index 22911641..7eb72f67 100644 --- a/application/controllers/Qrbcalc.php +++ b/application/controllers/Qrbcalc.php @@ -15,6 +15,10 @@ class Qrbcalc extends CI_Controller { public function index() { $data['page_title'] = "QRB Calculator"; + + $this->load->model('stations'); + $data['station_locator'] = $this->stations->find_gridsquare(); + $this->load->view('qrbcalc/index', $data); } @@ -29,9 +33,23 @@ class Qrbcalc extends CI_Controller { $measurement_base = $this->session->userdata('user_measurement_base'); } + switch ($measurement_base) { + case 'M': + $var_dist = " miles"; + break; + case 'N': + $var_dist = " nautic miles"; + break; + case 'K': + $var_dist = " kilometers"; + break; + } + $this->load->library('Qra'); $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); header('Content-Type: application/json'); diff --git a/application/libraries/Qra.php b/application/libraries/Qra.php index 322b3e1e..55cd9560 100644 --- a/application/libraries/Qra.php +++ b/application/libraries/Qra.php @@ -60,6 +60,16 @@ class Qra { // Return the distance return $total_distance; } + + /* + * Function returns just the bearing + * Input locator1 and locator2 + */ + function get_bearing($tx, $rx) { + $my = qra2latlong($tx); + $stn = qra2latlong($rx); + return get_bearing($my[0], $my[1], $stn[0], $stn[1]); + } } function distance($lat1, $lon1, $lat2, $lon2, $unit = 'M') { diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index efd10f7f..227d8118 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -454,13 +454,23 @@ function spawnQrbCalculator() { } 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': form.locator1.value, - 'locator2': form.locator2.value}, + data: {'locator1': locator1, + 'locator2': locator2}, success: function (html) { - $(".qrbResult").append(html['result']); + + var result = "
Negative latitudes are south of the equator, negative longitudes are west of Greenwich.
"; + result += ' ' + locator1.toUpperCase() + ' Latitude = ' + html['latlng1'][0] + ' Longitude = ' + html['latlng1'][1] + '
'; + result += ' ' + locator2.toUpperCase() + ' Latitude = ' + html['latlng2'][0] + ' Longitude = ' + html['latlng2'][1] + '
'; + result += 'Distance between ' + locator1.toUpperCase() + ' and ' + locator2.toUpperCase() + ' is ' + html['distance'] + '. and '; + result += 'the bearing is ' + html['bearing'] + '.
'; + + $(".qrbResult").html(result); newpath(html['latlng1'], html['latlng2']); } }); @@ -474,23 +484,31 @@ function newpath(locator1, locator2) { container._leaflet_id = null; } - const map = L.map('mapqrb').setView([30, 0], 1.5); + const map = new L.map('mapqrb').setView([30, 0], 1.5); var maidenhead = L.maidenheadqrb().addTo(map); - L.tileLayer('https://a.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', { - maxZoom: 10, - noWrap: false, - }).addTo(map); + var osmUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; + var osmAttrib='Map data © OpenStreetMap contributors'; + var osm = new L.TileLayer(osmUrl, {minZoom: 1, maxZoom: 9, attribution: osmAttrib}); + + var redIcon = L.icon({ + iconUrl: icon_dot_url, + iconSize: [10, 10], // size of the icon + }); + + map.addLayer(osm); + var marker = L.marker([locator1[0], locator1[1]], {icon: redIcon}); + map.addLayer(marker); + + var marker2 = L.marker([locator2[0], locator2[1]], {icon: redIcon}); + map.addLayer(marker2); const multiplelines = []; - //$.each(locs, function(){ multiplelines.push( new L.LatLng(locator1[0], locator1[1]), new L.LatLng(locator2[0], locator2[1]) ) - - //}); const geodesic = L.geodesic(multiplelines, { weight: 1, diff --git a/application/views/qrbcalc/index.php b/application/views/qrbcalc/index.php index b2619ba8..a58d3bef 100644 --- a/application/views/qrbcalc/index.php +++ b/application/views/qrbcalc/index.php @@ -3,7 +3,7 @@
Locator 1
- + " aria-label="locator1">