[Advanced Logbook] Added CQ and ITU zone to the bottom

This commit is contained in:
Andreas Kristiansen
2024-09-10 18:09:26 +02:00
parent b1ff0489dd
commit 73cc73691e
4 changed files with 70 additions and 1 deletions

View File

@@ -15,6 +15,8 @@
var lang_gen_hamradio_cq_zones = '<?= _pgettext("Map Options", "CQ Zones"); ?>';
var lang_gen_hamradio_itu_zones = '<?= _pgettext("Map Options", "ITU Zones"); ?>';
var lang_gen_hamradio_nightshadow = '<?= _pgettext("Map Options", "Night Shadow"); ?>';
var lang_gen_hamradio_ituzone = '<?= __("ITU Zone"); ?>';
var lang_gen_hamradio_cqzone = '<?= __("CQ Zone"); ?>';
<?php
echo "var homegrid ='" . strtoupper($homegrid[0]) . "';";
if (!isset($options)) {

View File

@@ -942,7 +942,7 @@ label {
#latDeg, #lngDeg {
width: 170px;
}
#locator, #distance, #bearing {
#locator, #distance, #bearing, #ituzonedisplay, #cqzonedisplay{
width: 120px;
}

View File

@@ -92,8 +92,71 @@ function onMapMove(event) {
$('#bearing').html(distance.deg + '°');
$('#distance').html(Math.round(distance.distance * 10) / 10 + ' ' +unit);
if (typeof zonestuff !== 'undefined' && zonestuff) {
const cqZone = findCQZone(event.latlng);
$('#cqzonedisplay').html(cqZone);
}
if (typeof ituzonestuff !== 'undefined' && ituzonestuff) {
const ituZone = findITUZone(event.latlng);
$('#ituzonedisplay').html(ituZone);
}
};
function findCQZone(latlng) {
let cqZone = null;
zonestuff.features.forEach(feature => {
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;

View File

@@ -242,6 +242,10 @@ function loadMap(data, iconsList) {
'<div class="cohidden col-auto text-success fw-bold" id="distance"></div>' +
'<div class="cohidden">' + lang_gen_hamradio_bearing + '&nbsp;</div>' +
'<div class="cohidden col-auto text-success fw-bold" id="bearing"></div>' +
'<div class="cohidden">' + lang_gen_hamradio_cqzone + '&nbsp;</div>' +
'<div class="cohidden col-auto text-success fw-bold" id="cqzonedisplay"></div>' +
'<div class="cohidden">' + lang_gen_hamradio_ituzone + '&nbsp;</div>' +
'<div class="cohidden col-auto text-success fw-bold" id="ituzonedisplay"></div>' +
'</div>');
$('.cohidden').show();
set_advancedmap_height();