fix(map3d): simplify projection loading release condition

This commit is contained in:
htlee 2026-02-15 14:45:31 +09:00
부모 f745bb16d7
커밋 9a9f7302cb

파일 보기

@ -605,7 +605,7 @@ export function Map3D({
setProjectionLoading(false); setProjectionLoading(false);
console.warn("Projection loading fallback timeout reached."); console.warn("Projection loading fallback timeout reached.");
} }
}, 18000); }, 3000);
} else { } else {
clearProjectionBusyTimer(); clearProjectionBusyTimer();
} }
@ -862,6 +862,41 @@ export function Map3D({
const maxRetries = 18; const maxRetries = 18;
const isTransition = projectionPrevRef.current !== projection; const isTransition = projectionPrevRef.current !== projection;
projectionPrevRef.current = projection; projectionPrevRef.current = projection;
let settleScheduled = false;
let settleCleanup: (() => void) | null = null;
const startProjectionSettle = () => {
if (!isTransition || settleScheduled) return;
settleScheduled = true;
const finalize = () => {
if (!cancelled && isTransition) setProjectionLoading(false);
};
const finalizeSoon = () => {
if (cancelled || !isTransition || projectionBusyRef.current === false) return;
if (!map.isStyleLoaded()) {
requestAnimationFrame(finalizeSoon);
return;
}
requestAnimationFrame(() => requestAnimationFrame(finalize));
};
const onIdle = () => finalizeSoon();
try {
map.on("idle", onIdle);
const styleReadyCleanup = onMapStyleReady(map, finalizeSoon);
settleCleanup = () => {
map.off("idle", onIdle);
styleReadyCleanup();
};
} catch {
requestAnimationFrame(finalize);
settleCleanup = null;
}
finalizeSoon();
};
if (isTransition) setProjectionLoading(true); if (isTransition) setProjectionLoading(true);
@ -985,17 +1020,7 @@ export function Map3D({
// ignore // ignore
} }
if (isTransition) { if (isTransition) {
const mercatorReady = projection === "mercator" && !!overlayRef.current; startProjectionSettle();
const globeReady = projection === "globe" && !!map.getLayer("deck-globe");
if (mercatorReady || globeReady) {
setProjectionLoading(false);
} else if (!cancelled && retries < maxRetries) {
retries += 1;
window.requestAnimationFrame(() => syncProjectionAndDeck());
return;
} else {
setProjectionLoading(false);
}
} }
pulseMapSync(); pulseMapSync();
}; };
@ -1007,6 +1032,7 @@ export function Map3D({
const stop = onMapStyleReady(map, syncProjectionAndDeck); const stop = onMapStyleReady(map, syncProjectionAndDeck);
return () => { return () => {
cancelled = true; cancelled = true;
if (settleCleanup) settleCleanup();
stop(); stop();
if (isTransition) setProjectionLoading(false); if (isTransition) setProjectionLoading(false);
}; };
@ -1014,6 +1040,7 @@ export function Map3D({
return () => { return () => {
cancelled = true; cancelled = true;
if (settleCleanup) settleCleanup();
if (isTransition) setProjectionLoading(false); if (isTransition) setProjectionLoading(false);
}; };
}, [projection, clearGlobeNativeLayers, ensureMercatorOverlay, removeLayerIfExists, setProjectionLoading]); }, [projection, clearGlobeNativeLayers, ensureMercatorOverlay, removeLayerIfExists, setProjectionLoading]);