Files
planet/frontend/public/earth/js/cluster-motion.js
T
rayd1o 05377bf5c6
ci / backend (push) Has been cancelled
ci / frontend (push) Has been cancelled
ci / delivery (push) Has been cancelled
release / images (push) Has been cancelled
release: bump version to 0.76.0
2026-09-30 17:49:29 +08:00

31 lines
1.2 KiB
JavaScript

export const CLUSTER_TWEEN_MS = 320;
export function createClusterTween(initial = 0) {
let from = initial, target = initial, startedAt = 0, current = initial;
const sample = now => {
const t = Math.max(0, Math.min(1, (now - startedAt) / CLUSTER_TWEEN_MS));
const eased = t < 0.5 ? 4 * t ** 3 : 1 - (-2 * t + 2) ** 3 / 2;
current = from + (target - from) * eased;
return current;
};
return {
sample,
target: () => target,
set(next, now) { if (next === target) return; from = sample(now); target = next; startedAt = now; },
active: now => Math.abs(sample(now) - target) > 1e-6,
};
}
export function coLocatedGroups(entries, tolerance = 0.00015) {
const groups = [];
for (const entry of [...entries].sort((a, b) => a.id.localeCompare(b.id))) {
if (!Number.isFinite(entry.lat) || !Number.isFinite(entry.lon)) continue;
const group = groups.find(items => {
const first = items[0];
const longitudeDelta = ((entry.lon - first.lon + 540) % 360) - 180;
return Math.hypot(entry.lat - first.lat, longitudeDelta * Math.cos(entry.lat * Math.PI / 180)) <= tolerance;
});
if (group) group.push(entry); else groups.push([entry]);
}
return groups.filter(group => group.length > 1);
}