From 73cc73691e3af118fed15e97d13ed403569a58fa Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Tue, 10 Sep 2024 18:09:26 +0200 Subject: [PATCH] [Advanced Logbook] Added CQ and ITU zone to the bottom --- application/views/logbookadvanced/index.php | 2 + assets/css/general.css | 2 +- assets/js/leaflet/geocoding.js | 63 +++++++++++++++++++++ assets/js/sections/logbookadvanced_map.js | 4 ++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/application/views/logbookadvanced/index.php b/application/views/logbookadvanced/index.php index e55507684..5816f433b 100644 --- a/application/views/logbookadvanced/index.php +++ b/application/views/logbookadvanced/index.php @@ -15,6 +15,8 @@ var lang_gen_hamradio_cq_zones = ''; var lang_gen_hamradio_itu_zones = ''; var lang_gen_hamradio_nightshadow = ''; + var lang_gen_hamradio_ituzone = ''; + var lang_gen_hamradio_cqzone = ''; { + try { + if (isMarkerInsidePolygon(latlng, feature)) { + cqZone = feature.properties.cq_zone_number; + } + } catch (error) { + console.error(error); + } + }); + + return cqZone; +} + +function findITUZone(latlng) { + if (85 < parseFloat(latlng.lat).toFixed(6)) + return "75"; + if (-85 > parseFloat(latlng.lat).toFixed(6)) + return "74"; + let ituZone = null; + ituzonestuff.features.forEach(feature => { + try { + if (isMarkerInsidePolygon(latlng, feature)) { + ituZone = feature.properties.itu_zone_number; + } + } catch (error) { + console.error(error); + } + }); + + return ituZone; +} + +function isMarkerInsidePolygon(marker, poly) { + const x = marker.lng; // Longitude + const y = marker.lat; // Latitude + + const polyPoints = poly.geometry.coordinates[0]; + let inside = false; + + for (let i = 0, j = polyPoints.length - 1; i < polyPoints.length; j = i++) { + const xi = polyPoints[i][0], yi = polyPoints[i][1]; + const xj = polyPoints[j][0], yj = polyPoints[j][1]; + + const intersect = ((yi > y) !== (yj > y)) && + (x < (xj - xi) * (y - yi) / (yj - yi) + xi); + if (intersect) inside = !inside; + } + + return inside; +} + function onMapClick(event) { var LatLng = event.latlng; var lat = LatLng.lat; diff --git a/assets/js/sections/logbookadvanced_map.js b/assets/js/sections/logbookadvanced_map.js index 842f35fe5..9c3e1bbe6 100644 --- a/assets/js/sections/logbookadvanced_map.js +++ b/assets/js/sections/logbookadvanced_map.js @@ -242,6 +242,10 @@ function loadMap(data, iconsList) { '
' + '
' + lang_gen_hamradio_bearing + ' 
' + '
' + + '
' + lang_gen_hamradio_cqzone + ' 
' + + '
' + + '
' + lang_gen_hamradio_ituzone + ' 
' + + '
' + ''); $('.cohidden').show(); set_advancedmap_height();