Fix orbit track splitting to only occur at true antimeridian crossings

The previous logic split the track whenever longitude jumped by more
than 180°, which could happen in cases other than actual antimeridian
crossings, causing gaps in the middle of the orbit track.

New logic only splits when one longitude is > 90° and the other is
< -90°, which specifically identifies crossings of the ±180° line.

Also changed segment minimum from 2 to 1 point to preserve all data.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
James Smith
2025-12-30 15:59:48 +00:00
parent 227b931c3d
commit 591e85aa2d
2 changed files with 24 additions and 19 deletions
+12 -9
View File
@@ -8380,21 +8380,23 @@
pastOrbitLine = null; pastOrbitLine = null;
} }
// Split ground track at antimeridian crossings // Split ground track only at true antimeridian crossings (±180° line)
const segments = []; const segments = [];
let currentSegment = []; let currentSegment = [];
for (let i = 0; i < pass.groundTrack.length; i++) { for (let i = 0; i < pass.groundTrack.length; i++) {
const p = pass.groundTrack[i]; const p = pass.groundTrack[i];
if (currentSegment.length > 0) { if (currentSegment.length > 0) {
const prevLon = currentSegment[currentSegment.length - 1][1]; const prevLon = currentSegment[currentSegment.length - 1][1];
if (Math.abs(p.lon - prevLon) > 180) { // Only split when crossing the antimeridian (one side > 90, other < -90)
if (currentSegment.length > 1) segments.push(currentSegment); const crossesAntimeridian = (prevLon > 90 && p.lon < -90) || (prevLon < -90 && p.lon > 90);
if (crossesAntimeridian) {
if (currentSegment.length >= 1) segments.push(currentSegment);
currentSegment = []; currentSegment = [];
} }
} }
currentSegment.push([p.lat, p.lon]); currentSegment.push([p.lat, p.lon]);
} }
if (currentSegment.length > 1) segments.push(currentSegment); if (currentSegment.length >= 1) segments.push(currentSegment);
// Draw ground track segments // Draw ground track segments
groundTrackLine = L.layerGroup(); groundTrackLine = L.layerGroup();
@@ -8510,7 +8512,7 @@
const pastPoints = orbitData.filter(p => p.past); const pastPoints = orbitData.filter(p => p.past);
const futurePoints = orbitData.filter(p => !p.past); const futurePoints = orbitData.filter(p => !p.past);
// Helper to split coords at antimeridian crossings // Helper to split coords only at true antimeridian crossings (±180° line)
function splitAtAntimeridian(points) { function splitAtAntimeridian(points) {
const segments = []; const segments = [];
let currentSegment = []; let currentSegment = [];
@@ -8518,15 +8520,16 @@
const p = points[i]; const p = points[i];
if (currentSegment.length > 0) { if (currentSegment.length > 0) {
const prevLon = currentSegment[currentSegment.length - 1][1]; const prevLon = currentSegment[currentSegment.length - 1][1];
// If longitude jumps more than 180°, start new segment // Only split when crossing the antimeridian (one side > 90, other < -90)
if (Math.abs(p.lon - prevLon) > 180) { const crossesAntimeridian = (prevLon > 90 && p.lon < -90) || (prevLon < -90 && p.lon > 90);
if (currentSegment.length > 1) segments.push(currentSegment); if (crossesAntimeridian) {
if (currentSegment.length >= 1) segments.push(currentSegment);
currentSegment = []; currentSegment = [];
} }
} }
currentSegment.push([p.lat, p.lon]); currentSegment.push([p.lat, p.lon]);
} }
if (currentSegment.length > 1) segments.push(currentSegment); if (currentSegment.length >= 1) segments.push(currentSegment);
return segments; return segments;
} }
+12 -10
View File
@@ -1185,7 +1185,7 @@
} }
if (pass && pass.groundTrack) { if (pass && pass.groundTrack) {
// Split track at antimeridian crossings to avoid lines across map // Split track only at true antimeridian crossings (±180° line)
const segments = []; const segments = [];
let currentSegment = []; let currentSegment = [];
@@ -1193,9 +1193,10 @@
const p = pass.groundTrack[i]; const p = pass.groundTrack[i];
if (currentSegment.length > 0) { if (currentSegment.length > 0) {
const prevLon = currentSegment[currentSegment.length - 1][1]; const prevLon = currentSegment[currentSegment.length - 1][1];
// If longitude jumps more than 180°, start new segment // Only split when crossing the antimeridian (one side > 90, other < -90)
if (Math.abs(p.lon - prevLon) > 180) { const crossesAntimeridian = (prevLon > 90 && p.lon < -90) || (prevLon < -90 && p.lon > 90);
if (currentSegment.length > 1) { if (crossesAntimeridian) {
if (currentSegment.length >= 1) {
segments.push(currentSegment); segments.push(currentSegment);
} }
currentSegment = []; currentSegment = [];
@@ -1203,7 +1204,7 @@
} }
currentSegment.push([p.lat, p.lon]); currentSegment.push([p.lat, p.lon]);
} }
if (currentSegment.length > 1) { if (currentSegment.length >= 1) {
segments.push(currentSegment); segments.push(currentSegment);
} }
@@ -1426,7 +1427,7 @@
groundMap.removeLayer(orbitTrack); groundMap.removeLayer(orbitTrack);
} }
// Split track at antimeridian crossings to avoid lines across map // Split track only at true antimeridian crossings (±180° line)
const segments = []; const segments = [];
let currentSegment = []; let currentSegment = [];
@@ -1434,9 +1435,10 @@
const p = pos.track[i]; const p = pos.track[i];
if (currentSegment.length > 0) { if (currentSegment.length > 0) {
const prevLon = currentSegment[currentSegment.length - 1][1]; const prevLon = currentSegment[currentSegment.length - 1][1];
// If longitude jumps more than 180°, start new segment // Only split when crossing the antimeridian (one side > 90, other < -90)
if (Math.abs(p.lon - prevLon) > 180) { const crossesAntimeridian = (prevLon > 90 && p.lon < -90) || (prevLon < -90 && p.lon > 90);
if (currentSegment.length >= 2) { if (crossesAntimeridian) {
if (currentSegment.length >= 1) {
segments.push(currentSegment); segments.push(currentSegment);
} }
currentSegment = []; currentSegment = [];
@@ -1444,7 +1446,7 @@
} }
currentSegment.push([p.lat, p.lon]); currentSegment.push([p.lat, p.lon]);
} }
if (currentSegment.length >= 2) { if (currentSegment.length >= 1) {
segments.push(currentSegment); segments.push(currentSegment);
} }