fix: insights crash, dup grids, .map() guards
Add /api/insights/cards endpoint with proper card format matching frontend expectations. Fixes "Cannot read properties of undefined (reading 'map')" crash. Switch frontend to use new endpoint. Replace alert marker rectangles with circleMarkers so they don't look like a second grid. Default showAlertMarkers to false. Add || [] guards on data.features.map() and alerts.map(). Reduce RiskMap grid count 3000→1500, debounce 150ms→300ms.
This commit is contained in:
@@ -298,6 +298,13 @@ export function LodGridLayer({
|
||||
});
|
||||
};
|
||||
|
||||
// Debounced full redraw (avoid thrashing during rapid pan/zoom)
|
||||
let redrawTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
const debouncedRedraw = () => {
|
||||
if (redrawTimer) clearTimeout(redrawTimer);
|
||||
redrawTimer = setTimeout(redraw, 300);
|
||||
};
|
||||
|
||||
// During pan: apply CSS transform to track tile movement (fixes drift)
|
||||
const onMove = () => {
|
||||
const drawn = drawnOriginRef.current;
|
||||
@@ -312,11 +319,11 @@ export function LodGridLayer({
|
||||
canvas.style.transform = `translate(${dx}px, ${dy}px)`;
|
||||
};
|
||||
|
||||
// On moveend/zoomend: reset transform and do full redraw
|
||||
// On moveend/zoomend: reset transform and do debounced full redraw
|
||||
const onMoveEnd = () => {
|
||||
canvas.style.transform = '';
|
||||
drawnOriginRef.current = null;
|
||||
redraw();
|
||||
debouncedRedraw();
|
||||
};
|
||||
|
||||
const onResize = () => redraw();
|
||||
@@ -339,6 +346,7 @@ export function LodGridLayer({
|
||||
map.off('resize', onResize);
|
||||
map.off('click', handleMapClick);
|
||||
if (animFrameRef.current) cancelAnimationFrame(animFrameRef.current);
|
||||
if (redrawTimer) clearTimeout(redrawTimer);
|
||||
pane.removeChild(canvas);
|
||||
if (pane.parentNode) pane.parentNode.removeChild(pane);
|
||||
canvasRef.current = null;
|
||||
|
||||
Reference in New Issue
Block a user