From 2eb89c1eff1e3e6311c6dd3a918f9d8479d8af46 Mon Sep 17 00:00:00 2001 From: Stanimir Stoyanov Date: Fri, 8 May 2020 10:45:06 +0300 Subject: [PATCH 1/4] Auto grid locator --- application/views/interface_assets/footer.php | 77 +++++++++++++++++-- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 5548cf4a..648f1af8 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -435,7 +435,8 @@ $(document).on('keypress',function(e) { if($('#locator').val() == "") { markers.clearLayers(); var marker = L.marker([result.dxcc.lat, result.dxcc.long]); - mymap.panTo([result.dxcc.lat, result.dxcc.long], 8); + mymap.setZoom(8); + mymap.panTo([result.dxcc.lat, result.dxcc.long]); markers.addLayer(marker).addTo(mymap); } } @@ -486,6 +487,70 @@ $(document).on('keypress',function(e) { } } + $('#qth').focusout(function() { + if ($('#locator').val() === '') { + var lat = 0; + var lon = 0; + $.ajax({ + async: false, + type: 'GET', + dataType: "json", + url: "https://nominatim.openstreetmap.org/search/?city=" + $(this).val() + "&format=json&addressdetails=1&limit=1", + data: {}, + success: function (data) { + if (typeof data[0].lat !== 'undefined') { + lat = parseFloat(data[0].lat); + } + if (typeof data[0].lon !== 'undefined') { + lon = parseFloat(data[0].lon); + } + }, + }); + if (lat !== 0 && lon !== 0) { + var qthloc = LatLng2Loc(lat, lon, 10); + if (qthloc.length > 0) { + $('#locator').val(qthloc.substr(0, 6)).trigger('focusout'); + } + } + } + }); + + LatLng2Loc = function(y, x, num) { + if (x < -180) { + x = x + 360; + } + if (x > 180) { + x = x - 360; + } + var yqth, yi, yk, ydiv, yres, ylp, y; + var ycalc = new Array(0, 0, 0); + var yn = new Array(0, 0, 0, 0, 0, 0, 0); + + var ydiv_arr = new Array(10, 1, 1 / 24, 1 / 240, 1 / 240 / 24); + ycalc[0] = (x + 180) / 2; + ycalc[1] = y + 90; + + for (yi = 0; yi < 2; yi++) { + for (yk = 0; yk < 5; yk++) { + ydiv = ydiv_arr[yk]; + yres = ycalc[yi] / ydiv; + ycalc[yi] = yres; + if (ycalc[yi] > 0) ylp = Math.floor(yres); else ylp = Math.ceil(yres); + ycalc[yi] = (ycalc[yi] - ylp) * ydiv; + yn[2 * yk + yi] = ylp; + } + } + + var qthloc = ""; + if (num >= 2) qthloc += String.fromCharCode(yn[0] + 0x41) + String.fromCharCode(yn[1] + 0x41); + if (num >= 4) qthloc += String.fromCharCode(yn[2] + 0x30) + String.fromCharCode(yn[3] + 0x30); + if (num >= 6) qthloc += String.fromCharCode(yn[4] + 0x41) + String.fromCharCode(yn[5] + 0x41); + if (num >= 8) qthloc += ' ' + String.fromCharCode(yn[6] + 0x30) + String.fromCharCode(yn[7] + 0x30); + if (num >= 10) qthloc += String.fromCharCode(yn[8] + 0x61) + String.fromCharCode(yn[9] + 0x61); + return qthloc; + + } + $("#callsign").focusout(function() { if ($(this).val().length >= 3) { @@ -566,12 +631,13 @@ $(document).on('keypress',function(e) { // Set Map to Lat/Long markers.clearLayers(); + mymap.setZoom(8); if (typeof result.latlng !== "undefined" && result.latlng !== false) { var marker = L.marker([result.latlng[0], result.latlng[1]]); - mymap.panTo([result.latlng[0], result.latlng[1]], 8); + mymap.panTo([result.latlng[0], result.latlng[1]]); } else { var marker = L.marker([result.dxcc.lat, result.dxcc.long]); - mymap.panTo([result.dxcc.lat, result.dxcc.long], 8); + mymap.panTo([result.dxcc.lat, result.dxcc.long]); } markers.addLayer(marker).addTo(mymap); @@ -737,14 +803,15 @@ $(document).on('keypress',function(e) { } } - if(qra_input.length >= 4) { + if(qra_input.length >= 4 && $(this).val().length > 0) { $.getJSON('logbook/qralatlngjson/' + $(this).val(), function(result) { // Set Map to Lat/Long markers.clearLayers(); if (typeof result !== "undefined") { var marker = L.marker([result[0], result[1]]); - mymap.setView([result[0], result[1]], 8); + mymap.setZoom(8); + mymap.panTo([result[0], result[1]]); } markers.addLayer(marker).addTo(mymap); }) From 256635919fa3dd2a7656efd3c349ddee6207a4e1 Mon Sep 17 00:00:00 2001 From: Stanimir Stoyanov Date: Fri, 8 May 2020 14:52:53 +0300 Subject: [PATCH 2/4] Ability to disable the auto QTH filler based on the location string --- application/config/cloudlog.php | 16 ++++++++++++++++ application/views/interface_assets/footer.php | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/application/config/cloudlog.php b/application/config/cloudlog.php index 0d2f6bf9..9fda1c61 100644 --- a/application/config/cloudlog.php +++ b/application/config/cloudlog.php @@ -124,3 +124,19 @@ $config['qso_date_format'] = "d/m/y"; */ $config['map_6digit_grids'] = FALSE; + + +/* +|-------------------------------------------------------------------------- +| Automatically populate the QTH +|-------------------------------------------------------------------------- +| +| Setting this to TRUE allows the QTH locator to be pre-filled +| based on the person's location when creating new QSO. +| OSM's Nominatim API is being used for that purpose +| +| Default is: TRUE +| +*/ + +$config['qso_auto_qth'] = TRUE; diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 648f1af8..51e4b628 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -486,7 +486,7 @@ $(document).on('keypress',function(e) { }) } } - +config->item('qso_auto_qth')) { ?> $('#qth').focusout(function() { if ($('#locator').val() === '') { var lat = 0; @@ -548,8 +548,8 @@ $(document).on('keypress',function(e) { if (num >= 8) qthloc += ' ' + String.fromCharCode(yn[6] + 0x30) + String.fromCharCode(yn[7] + 0x30); if (num >= 10) qthloc += String.fromCharCode(yn[8] + 0x61) + String.fromCharCode(yn[9] + 0x61); return qthloc; - } + $("#callsign").focusout(function() { From 4372e360729bd3a745f2d73bac269332974529a7 Mon Sep 17 00:00:00 2001 From: Stanimir Stoyanov Date: Sat, 9 May 2020 19:41:02 +0300 Subject: [PATCH 3/4] auto_qth_qso to be false by default --- application/config/cloudlog.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/config/cloudlog.php b/application/config/cloudlog.php index 9fda1c61..04bddab9 100644 --- a/application/config/cloudlog.php +++ b/application/config/cloudlog.php @@ -139,4 +139,4 @@ $config['map_6digit_grids'] = FALSE; | */ -$config['qso_auto_qth'] = TRUE; +$config['qso_auto_qth'] = FALSE; From 596d662c419a725bbdaa61bec0847cbe23fe3607 Mon Sep 17 00:00:00 2001 From: Stanimir Stoyanov Date: Sat, 9 May 2020 19:44:07 +0300 Subject: [PATCH 4/4] auto_qth_qso to be false by default --- application/config/cloudlog.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/config/cloudlog.php b/application/config/cloudlog.php index 04bddab9..a71ec45e 100644 --- a/application/config/cloudlog.php +++ b/application/config/cloudlog.php @@ -135,7 +135,7 @@ $config['map_6digit_grids'] = FALSE; | based on the person's location when creating new QSO. | OSM's Nominatim API is being used for that purpose | -| Default is: TRUE +| Default is: FALSE | */