Sternhimmel läd jetzt sauber
This commit is contained in:
+72
-31
@@ -6,12 +6,12 @@ ini_set('memory_limit', '512M');
|
|||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
$loggedIn = isset($_SESSION['user_id']);
|
$loggedIn = isset($_SESSION['user_id']);
|
||||||
|
$starsApiRequested = isset($_GET['stars_api']) && (string)$_GET['stars_api'] === '1';
|
||||||
$pageTitle = 'Sternenhimmel - AstroTools';
|
$pageTitle = 'Sternenhimmel - AstroTools';
|
||||||
$bodyClass = 'sternenhimmel-page';
|
$bodyClass = 'sternenhimmel-page';
|
||||||
|
|
||||||
$constellationData = ['constellations' => []];
|
$constellationData = ['constellations' => []];
|
||||||
$constellationDataError = null;
|
$constellationDataError = null;
|
||||||
$starData = [];
|
|
||||||
$starDataError = null;
|
$starDataError = null;
|
||||||
$messierData = [];
|
$messierData = [];
|
||||||
$messierDataError = null;
|
$messierDataError = null;
|
||||||
@@ -105,31 +105,41 @@ try {
|
|||||||
static fn(array $a, array $b): int => strcmp($a['id'], $b['id'])
|
static fn(array $a, array $b): int => strcmp($a['id'], $b['id'])
|
||||||
);
|
);
|
||||||
|
|
||||||
$constellationData['constellations'] = array_values($constellations);
|
if ($starsApiRequested) {
|
||||||
|
$starData = [];
|
||||||
|
$starStmt = $planetariumPdo->query(
|
||||||
|
"SELECT hip, proper, bayer, con, spect, mag, ci, rarad, decrad
|
||||||
|
FROM star_hipparcos
|
||||||
|
WHERE mag IS NOT NULL
|
||||||
|
AND rarad IS NOT NULL
|
||||||
|
AND decrad IS NOT NULL
|
||||||
|
AND mag <= " . (float)$starDbMagLimit . "
|
||||||
|
ORDER BY mag ASC"
|
||||||
|
);
|
||||||
|
while ($row = $starStmt->fetch()) {
|
||||||
|
$starData[] = [
|
||||||
|
'hip' => $row['hip'] !== null ? (int)$row['hip'] : null,
|
||||||
|
'proper' => trim((string)($row['proper'] ?? '')),
|
||||||
|
'bayer' => trim((string)($row['bayer'] ?? '')),
|
||||||
|
'con' => trim((string)($row['con'] ?? '')),
|
||||||
|
'spect' => trim((string)($row['spect'] ?? '')),
|
||||||
|
'ra' => (float)$row['rarad'],
|
||||||
|
'dec' => (float)$row['decrad'],
|
||||||
|
'mag' => (float)$row['mag'],
|
||||||
|
'ci' => $row['ci'] !== null ? (float)$row['ci'] : null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
$starStmt = $planetariumPdo->query(
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
"SELECT hip, proper, bayer, con, spect, mag, ci, rarad, decrad
|
echo json_encode([
|
||||||
FROM star_hipparcos
|
'ok' => true,
|
||||||
WHERE mag IS NOT NULL
|
'stars' => $starData,
|
||||||
AND rarad IS NOT NULL
|
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
AND decrad IS NOT NULL
|
exit;
|
||||||
AND mag <= " . (float)$starDbMagLimit . "
|
|
||||||
ORDER BY mag ASC"
|
|
||||||
);
|
|
||||||
while ($row = $starStmt->fetch()) {
|
|
||||||
$starData[] = [
|
|
||||||
'hip' => $row['hip'] !== null ? (int)$row['hip'] : null,
|
|
||||||
'proper' => trim((string)($row['proper'] ?? '')),
|
|
||||||
'bayer' => trim((string)($row['bayer'] ?? '')),
|
|
||||||
'con' => trim((string)($row['con'] ?? '')),
|
|
||||||
'spect' => trim((string)($row['spect'] ?? '')),
|
|
||||||
'ra' => (float)$row['rarad'],
|
|
||||||
'dec' => (float)$row['decrad'],
|
|
||||||
'mag' => (float)$row['mag'],
|
|
||||||
'ci' => $row['ci'] !== null ? (float)$row['ci'] : null,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$constellationData['constellations'] = array_values($constellations);
|
||||||
|
|
||||||
$messierStmt = $planetariumPdo->query(
|
$messierStmt = $planetariumPdo->query(
|
||||||
"SELECT messier, name, object_type_abrev, ra_deg, dec_deg, v_mag, major_axis
|
"SELECT messier, name, object_type_abrev, ra_deg, dec_deg, v_mag, major_axis
|
||||||
FROM dso_objects
|
FROM dso_objects
|
||||||
@@ -177,6 +187,15 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
|
if ($starsApiRequested) {
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
http_response_code(500);
|
||||||
|
echo json_encode([
|
||||||
|
'ok' => false,
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
$constellationDataError = $e->getMessage();
|
$constellationDataError = $e->getMessage();
|
||||||
$starDataError = $e->getMessage();
|
$starDataError = $e->getMessage();
|
||||||
$messierDataError = $e->getMessage();
|
$messierDataError = $e->getMessage();
|
||||||
@@ -190,10 +209,6 @@ $constellationDataErrorJson = json_encode(
|
|||||||
$constellationDataError,
|
$constellationDataError,
|
||||||
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
|
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
|
||||||
);
|
);
|
||||||
$starDataJson = json_encode(
|
|
||||||
$starData,
|
|
||||||
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
|
|
||||||
);
|
|
||||||
$starDataErrorJson = json_encode(
|
$starDataErrorJson = json_encode(
|
||||||
$starDataError,
|
$starDataError,
|
||||||
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
|
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
|
||||||
@@ -549,7 +564,7 @@ let showStars = true;
|
|||||||
// ═══════════════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════════════
|
||||||
const EMBEDDED_CONSTELLATION_DATA = <?php echo $constellationDataJson ?: '{"constellations":[]}'; ?>;
|
const EMBEDDED_CONSTELLATION_DATA = <?php echo $constellationDataJson ?: '{"constellations":[]}'; ?>;
|
||||||
const EMBEDDED_CONSTELLATION_ERROR = <?php echo $constellationDataErrorJson ?: 'null'; ?>;
|
const EMBEDDED_CONSTELLATION_ERROR = <?php echo $constellationDataErrorJson ?: 'null'; ?>;
|
||||||
const EMBEDDED_STAR_DATA = <?php echo $starDataJson ?: '[]'; ?>;
|
const STAR_DATA_URL = 'sternenhimmel.php?stars_api=1';
|
||||||
const EMBEDDED_STAR_ERROR = <?php echo $starDataErrorJson ?: 'null'; ?>;
|
const EMBEDDED_STAR_ERROR = <?php echo $starDataErrorJson ?: 'null'; ?>;
|
||||||
const EMBEDDED_MESSIER_DATA = <?php echo $messierDataJson ?: '[]'; ?>;
|
const EMBEDDED_MESSIER_DATA = <?php echo $messierDataJson ?: '[]'; ?>;
|
||||||
const EMBEDDED_MESSIER_ERROR = <?php echo $messierDataErrorJson ?: 'null'; ?>;
|
const EMBEDDED_MESSIER_ERROR = <?php echo $messierDataErrorJson ?: 'null'; ?>;
|
||||||
@@ -1805,8 +1820,7 @@ function finalizeStarLoad() {
|
|||||||
if (AUTO_IMG) autoExportPng();
|
if (AUTO_IMG) autoExportPng();
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadEmbeddedStarsAsync() {
|
function processStarBatch(source) {
|
||||||
const source = Array.isArray(EMBEDDED_STAR_DATA) ? EMBEDDED_STAR_DATA : [];
|
|
||||||
const total = source.length;
|
const total = source.length;
|
||||||
const chunkSize = total > 60000 ? 1800 : 1200;
|
const chunkSize = total > 60000 ? 1800 : 1200;
|
||||||
let index = 0;
|
let index = 0;
|
||||||
@@ -1862,6 +1876,27 @@ function loadEmbeddedStarsAsync() {
|
|||||||
window.setTimeout(processChunk, 0);
|
window.setTimeout(processChunk, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function loadEmbeddedStarsAsync() {
|
||||||
|
updateStarLoadingUi(0, 1);
|
||||||
|
if (starLoadingNote) starLoadingNote.textContent = 'Sternkatalog wird vom Server geladen ...';
|
||||||
|
|
||||||
|
const response = await fetch(STAR_DATA_URL, {
|
||||||
|
headers: { 'Accept': 'application/json' },
|
||||||
|
cache: 'no-store'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Sternkatalog konnte nicht geladen werden (HTTP ' + response.status + ')');
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = await response.json();
|
||||||
|
if (!payload || payload.ok !== true || !Array.isArray(payload.stars)) {
|
||||||
|
throw new Error(payload && payload.error ? payload.error : 'Ungültige Sternkatalog-Antwort');
|
||||||
|
}
|
||||||
|
|
||||||
|
processStarBatch(payload.stars);
|
||||||
|
}
|
||||||
|
|
||||||
// Manueller Fallback über Datei-Dialog
|
// Manueller Fallback über Datei-Dialog
|
||||||
document.getElementById('fileInput').addEventListener('change', function(e) {
|
document.getElementById('fileInput').addEventListener('change', function(e) {
|
||||||
const file = e.target.files[0];
|
const file = e.target.files[0];
|
||||||
@@ -2017,7 +2052,13 @@ syncMessierMagLimitUi();
|
|||||||
setLocation(LAT_DEG, LON_DEG, ELEV_M, HEADER_LOCATION.name || 'Standard-Standort', HEADER_LOCATION.id ?? '');
|
setLocation(LAT_DEG, LON_DEG, ELEV_M, HEADER_LOCATION.name || 'Standard-Standort', HEADER_LOCATION.id ?? '');
|
||||||
resize();
|
resize();
|
||||||
window.requestAnimationFrame(() => {
|
window.requestAnimationFrame(() => {
|
||||||
window.setTimeout(loadEmbeddedStarsAsync, 40);
|
window.setTimeout(() => {
|
||||||
|
loadEmbeddedStarsAsync().catch(err => {
|
||||||
|
console.warn('Sterndaten aus der Datenbank nicht geladen:', err);
|
||||||
|
if (starLoadingStatus) starLoadingStatus.textContent = 'Fehler';
|
||||||
|
if (starLoadingNote) starLoadingNote.textContent = err && err.message ? err.message : 'Sternkatalog konnte nicht geladen werden';
|
||||||
|
});
|
||||||
|
}, 40);
|
||||||
});
|
});
|
||||||
|
|
||||||
}); // end window.onload
|
}); // end window.onload
|
||||||
|
|||||||
Reference in New Issue
Block a user