mirror of
https://github.com/magicbug/Cloudlog
synced 2024-11-22 00:07:14 +00:00
[Dashboard] Fixes JS errors when loading map when theres no qsos
This commit is contained in:
parent
f5ba31df30
commit
c050a42b35
@ -80,13 +80,23 @@ class Map extends CI_Controller {
|
||||
$offset = (intval($this->input->post('offset'))>0)?xss_clean($this->input->post('offset')):null;
|
||||
$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');
|
||||
echo json_encode(array_merge($plot_array, $station_array));
|
||||
}
|
||||
if(empty($qsos)) {
|
||||
// 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));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -895,30 +895,34 @@ if ($this->session->userdata('user_id') != null) {
|
||||
fetch(qso_loc)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
var newMarkers = {};
|
||||
data.markers.forEach(marker => {
|
||||
var key = `${marker.lat},${marker.lng}`;
|
||||
var html = `<h3>${marker.flag}${marker.label}</h3> ${marker.html}`;
|
||||
newMarkers[key] = marker;
|
||||
if (!markers[key]) {
|
||||
var icon = L.divIcon({
|
||||
className: 'custom-icon',
|
||||
html: `<i class="${iconsList.qso.icon}" style="color:${iconsList.qso.color}"></i>`
|
||||
});
|
||||
|
||||
L.marker([marker.lat, marker.lng], {
|
||||
icon: icon
|
||||
})
|
||||
.addTo(map)
|
||||
.bindPopup(html);
|
||||
if (data.error !== "No QSOs found") {
|
||||
var newMarkers = {};
|
||||
data.markers.forEach(marker => {
|
||||
var key = `${marker.lat},${marker.lng}`;
|
||||
var html = `<h3>${marker.flag}${marker.label}</h3> ${marker.html}`;
|
||||
newMarkers[key] = marker;
|
||||
if (!markers[key]) {
|
||||
var icon = L.divIcon({
|
||||
className: 'custom-icon',
|
||||
html: `<i class="${iconsList.qso.icon}" style="color:${iconsList.qso.color}"></i>`
|
||||
});
|
||||
|
||||
L.marker([marker.lat, marker.lng], {
|
||||
icon: icon
|
||||
})
|
||||
.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;
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user