deploy
This commit is contained in:
parent
273d7a83ee
commit
084117cea8
48 changed files with 2283 additions and 890 deletions
|
|
@ -10,6 +10,7 @@ import type { MapFlyTo } from './types';
|
|||
|
||||
type MapData = ReturnType<typeof useMapData>;
|
||||
type RightPaneTab = 'properties' | 'area';
|
||||
const SCREENSHOT_MAP_IDLE_FALLBACK_MS = 1000;
|
||||
|
||||
export function useInitialMapPageView(
|
||||
mapData: MapData,
|
||||
|
|
@ -110,36 +111,72 @@ export function useMobileBackNavigationGuard(isMobile: boolean) {
|
|||
interface UseScreenshotReadySignalOptions {
|
||||
screenshotMode?: boolean;
|
||||
loading: boolean;
|
||||
boundsReady: boolean;
|
||||
dataLength: number;
|
||||
postcodeDataLength: number;
|
||||
usePostcodeView: boolean;
|
||||
licenseRequired: boolean;
|
||||
}
|
||||
|
||||
export function useScreenshotReadySignal({
|
||||
screenshotMode,
|
||||
loading,
|
||||
boundsReady,
|
||||
dataLength,
|
||||
postcodeDataLength,
|
||||
usePostcodeView,
|
||||
licenseRequired,
|
||||
}: UseScreenshotReadySignalOptions) {
|
||||
useEffect(() => {
|
||||
if (screenshotMode && !loading) {
|
||||
const hasData = usePostcodeView ? postcodeDataLength > 0 : dataLength > 0;
|
||||
if (hasData) {
|
||||
// Wait for both deck.gl data and MapLibre base map tile rendering.
|
||||
const waitAndSignal = () => {
|
||||
if (window.__map_idle) {
|
||||
requestAnimationFrame(() => {
|
||||
requestAnimationFrame(() => {
|
||||
window.__screenshot_ready = true;
|
||||
});
|
||||
});
|
||||
} else {
|
||||
requestAnimationFrame(waitAndSignal);
|
||||
}
|
||||
};
|
||||
waitAndSignal();
|
||||
if (!screenshotMode || loading || !boundsReady) return;
|
||||
|
||||
const hasData = usePostcodeView ? postcodeDataLength > 0 : dataLength > 0;
|
||||
if (!hasData && !licenseRequired) return;
|
||||
|
||||
let cancelled = false;
|
||||
let signalled = false;
|
||||
let frameId: number | null = null;
|
||||
let timeoutId: number | null = null;
|
||||
|
||||
const signalReady = () => {
|
||||
if (cancelled || signalled) return;
|
||||
signalled = true;
|
||||
if (timeoutId != null) window.clearTimeout(timeoutId);
|
||||
if (frameId != null) window.cancelAnimationFrame(frameId);
|
||||
requestAnimationFrame(() => {
|
||||
requestAnimationFrame(() => {
|
||||
if (!cancelled) window.__screenshot_ready = true;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const waitAndSignal = () => {
|
||||
if (window.__map_idle) {
|
||||
signalReady();
|
||||
} else {
|
||||
frameId = requestAnimationFrame(waitAndSignal);
|
||||
}
|
||||
}
|
||||
}, [screenshotMode, loading, dataLength, postcodeDataLength, usePostcodeView]);
|
||||
};
|
||||
|
||||
// In webpack dev mode MapLibre's idle event can be delayed by the dev
|
||||
// client/HMR churn even after data has rendered. Keep production-quality
|
||||
// waiting when idle fires, but avoid forcing the screenshot service to hit
|
||||
// its much longer timeout in local development.
|
||||
timeoutId = window.setTimeout(signalReady, SCREENSHOT_MAP_IDLE_FALLBACK_MS);
|
||||
waitAndSignal();
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
if (timeoutId != null) window.clearTimeout(timeoutId);
|
||||
if (frameId != null) window.cancelAnimationFrame(frameId);
|
||||
};
|
||||
}, [
|
||||
screenshotMode,
|
||||
loading,
|
||||
boundsReady,
|
||||
dataLength,
|
||||
postcodeDataLength,
|
||||
usePostcodeView,
|
||||
licenseRequired,
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue