mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Merge pull request #2798 from AndreasK79/gridmap_country_center
[Gridmap] Add country name to legend, and set map center
This commit is contained in:
@@ -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']);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@
|
||||
</select>
|
||||
</div>
|
||||
<?php if(count($countries->result()) > 0) { ?>
|
||||
<label class="col-md-2" for="country">Country</label>
|
||||
<label class="col-md-2" for="country">DXCC</label>
|
||||
<div class="col-sm-3">
|
||||
<select class="form-select form-select-sm" id="dxcc">
|
||||
<option value="All"><?= __("All") ?></option>
|
||||
|
||||
@@ -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 = '<div align="right" class="legendClose"><small><a href="javascript: hideLegend();">X</a></small></div>';
|
||||
// Add country name if selected
|
||||
const countryName = getSelectedCountryName();
|
||||
if (countryName) {
|
||||
html += '<h4>DXCC: ' + countryName + '</h4>';
|
||||
}
|
||||
|
||||
html += "<table border=\"0\">";
|
||||
html += '<i style="background: green"></i><span>' + gridsquares_gridsquares_confirmed + ' ('+grid_four_confirmed.length+')</span><br>';
|
||||
html += '<i style="background: red"></i><span>' + gridsquares_gridsquares_not_confirmed + ' ('+(grid_four.length - grid_four_confirmed.length)+')</span><br>';
|
||||
@@ -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 = ({
|
||||
|
||||
Reference in New Issue
Block a user