[Dashboard] Fixes JS errors when loading map when theres no qsos

This commit is contained in:
Peter Goodhall 2024-06-19 13:46:31 +01:00
parent f5ba31df30
commit c050a42b35
2 changed files with 45 additions and 31 deletions

View File

@ -80,13 +80,23 @@ class Map extends CI_Controller {
$offset = (intval($this->input->post('offset'))>0)?xss_clean($this->input->post('offset')):null; $offset = (intval($this->input->post('offset'))>0)?xss_clean($this->input->post('offset')):null;
$qsos = $this->logbook_model->get_qsos($nb_qso, $offset); $qsos = $this->logbook_model->get_qsos($nb_qso, $offset);
} }
// [PLOT] ADD plot //
$plot_array = $this->logbook_model->get_plot_array_for_map($qsos->result());
// [MAP Custom] ADD Station //
$station_array = $this->Stations->get_station_array_for_map();
header('Content-Type: application/json; charset=utf-8'); if(empty($qsos)) {
echo json_encode(array_merge($plot_array, $station_array)); // Handle the case where $qsos is empty
}
} // return json with error "No QSOs found"
header('Content-Type: application/json; charset=utf-8');
echo json_encode(array('error' => 'No QSOs found'));
} else {
// Handle the case where $qsos is not empty
// [PLOT] ADD plot //
$plot_array = $this->logbook_model->get_plot_array_for_map($qsos->result());
// [MAP Custom] ADD Station //
$station_array = $this->Stations->get_station_array_for_map();
header('Content-Type: application/json; charset=utf-8');
echo json_encode(array_merge($plot_array, $station_array));
}
}
}

View File

@ -895,30 +895,34 @@ if ($this->session->userdata('user_id') != null) {
fetch(qso_loc) fetch(qso_loc)
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
var newMarkers = {}; if (data.error !== "No QSOs found") {
data.markers.forEach(marker => { var newMarkers = {};
var key = `${marker.lat},${marker.lng}`; data.markers.forEach(marker => {
var html = `<h3>${marker.flag}${marker.label}</h3> ${marker.html}`; var key = `${marker.lat},${marker.lng}`;
newMarkers[key] = marker; var html = `<h3>${marker.flag}${marker.label}</h3> ${marker.html}`;
if (!markers[key]) { newMarkers[key] = marker;
var icon = L.divIcon({ if (!markers[key]) {
className: 'custom-icon', var icon = L.divIcon({
html: `<i class="${iconsList.qso.icon}" style="color:${iconsList.qso.color}"></i>` className: 'custom-icon',
}); html: `<i class="${iconsList.qso.icon}" style="color:${iconsList.qso.color}"></i>`
});
L.marker([marker.lat, marker.lng], {
icon: icon L.marker([marker.lat, marker.lng], {
}) icon: icon
.addTo(map) })
.bindPopup(html); .addTo(map)
.bindPopup(html);
}
});
Object.keys(markers).forEach(key => {
if (!newMarkers[key]) {
map.removeLayer(markers[key]);
}
});
markers = newMarkers;
} else {
console.log("No QSOs found to populate dashboard map.");
} }
});
Object.keys(markers).forEach(key => {
if (!newMarkers[key]) {
map.removeLayer(markers[key]);
}
});
markers = newMarkers;
}); });
} }