From a87c8cd13f2912578426a95078ed8f44b200c042 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Thu, 8 Jan 2026 13:02:34 +0100 Subject: [PATCH] [Gridmap] Add country name to legend, and set map center --- application/controllers/Gridmap.php | 2 ++ application/models/Gridmap_model.php | 20 ++++++++++++ assets/js/sections/gridmap.js | 46 +++++++++++++++++++++++----- 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/application/controllers/Gridmap.php b/application/controllers/Gridmap.php index 152e0f460..5082220f6 100644 --- a/application/controllers/Gridmap.php +++ b/application/controllers/Gridmap.php @@ -72,6 +72,8 @@ class Gridmap extends CI_Controller { $this->load->model('gridmap_model'); + $data['country_coords'] = $this->gridmap_model->get_coordinates_for_dxcc($dxcc); + $data['grids'] = $this->gridmap_model->get_grids_for_country($dxcc); $data['grid_count'] = count($data['grids']); diff --git a/application/models/Gridmap_model.php b/application/models/Gridmap_model.php index b6f2e5872..014b86d61 100644 --- a/application/models/Gridmap_model.php +++ b/application/models/Gridmap_model.php @@ -390,4 +390,24 @@ class Gridmap_model extends CI_Model { return $gridarray; } + + function get_coordinates_for_dxcc($dxcc) { + // Get country coordinates if a specific country is selected + $country_coords = null; + if ($dxcc && $dxcc != 'All') { + // Query dxcc_entities table for country info + $sql = "SELECT adif, lat, `long`, name FROM dxcc_entities WHERE adif = ?"; + $query = $this->db->query($sql, array($dxcc)); + + if ($query && $query->num_rows() > 0) { + $country_info = $query->row(); + $country_coords = [ + 'lat' => (float)$country_info->lat, + 'long' => (float)$country_info->long, + 'name' => $country_info->name + ]; + } + } + return $country_coords; + } } diff --git a/assets/js/sections/gridmap.js b/assets/js/sections/gridmap.js index a8734b44c..bcd2d0d44 100644 --- a/assets/js/sections/gridmap.js +++ b/assets/js/sections/gridmap.js @@ -132,7 +132,7 @@ function gridPlot(form, visitor=true) { grid_six_confirmed = data.grid_6char_confirmed; grids = data.grids; grid_max = data.grid_count; - plot(visitor, grid_two, grid_four, grid_six, grid_two_confirmed, grid_four_confirmed, grid_six_confirmed, grids, grid_max); + plot(visitor, grid_two, grid_four, grid_six, grid_two_confirmed, grid_four_confirmed, grid_six_confirmed, grids, grid_max, data.country_coords); }, error: function (data) { @@ -143,17 +143,26 @@ function gridPlot(form, visitor=true) { }; } -function plot(visitor, grid_two, grid_four, grid_six, grid_two_confirmed, grid_four_confirmed, grid_six_confirmed, grids, grid_max) { - var layer = L.tileLayer(jslayer, { +function plot(visitor, grid_two, grid_four, grid_six, grid_two_confirmed, grid_four_confirmed, grid_six_confirmed, grids, grid_max, country_coords) { + let layer = L.tileLayer(jslayer, { maxZoom: 12, attribution: jsattribution, id: 'mapbox.streets' }); + // Set map center and zoom based on country selection + let mapCenter = [19, 0]; + let mapZoom = 3; + + if (country_coords && country_coords.lat && country_coords.long) { + mapCenter = [country_coords.lat, country_coords.long]; + mapZoom = 5; // Zoom in closer for country view + } + map = L.map('gridsquare_map', { layers: [layer], - center: [19, 0], - zoom: 3, + center: mapCenter, + zoom: mapZoom, minZoom: 2, fullscreenControl: true, fullscreenControlOptions: { @@ -162,7 +171,7 @@ function plot(visitor, grid_two, grid_four, grid_six, grid_two_confirmed, grid_f }); if (visitor != true) { - var printer = L.easyPrint({ + let printer = L.easyPrint({ tileLayer: layer, sizeModes: ['Current'], filename: 'myMap', @@ -172,7 +181,7 @@ function plot(visitor, grid_two, grid_four, grid_six, grid_two_confirmed, grid_f } /*Legend specific*/ - var legend = L.control({ position: "topright" }); + let legend = L.control({ position: "topright" }); if (grids != '') { @@ -180,6 +189,12 @@ function plot(visitor, grid_two, grid_four, grid_six, grid_two_confirmed, grid_f let div = L.DomUtil.create("div", "legend"); div.setAttribute('id', 'gridmapLegend'); html = '
X
'; + // Add country name if selected + const countryName = getSelectedCountryName(); + if (countryName) { + html += '

Country: ' + countryName + '

'; + } + html += ""; html += '' + gridsquares_gridsquares_confirmed + ' ('+grid_four_confirmed.length+')
'; html += '' + gridsquares_gridsquares_not_confirmed + ' ('+(grid_four.length - grid_four_confirmed.length)+')
'; @@ -214,6 +229,23 @@ function plot(visitor, grid_two, grid_four, grid_six, grid_two_confirmed, grid_f } } +// Get selected country name from multiselect +function getSelectedCountryName() { + const dxccSelect = $('#dxcc'); + const selectedValues = dxccSelect.val(); + + if (!selectedValues || selectedValues[0] === 'All') { + return null; + } + + // Get the text of selected options + const selectedText = dxccSelect.find('option:selected').map(function() { + return $(this).text(); + }).get(); + + return selectedText.join(', '); +} + function spawnGridsquareModal(loc_4char) { if (!(modalloading)) { var ajax_data = ({