From 2eb182fccc4718620440e80cc3b2f11104925d06 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 26 Dec 2025 01:48:59 -0500 Subject: [PATCH] Restrict map to bounds-only posts --- src/components/Map/usePostsEngine.js | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/src/components/Map/usePostsEngine.js b/src/components/Map/usePostsEngine.js index 0943321..582b0a7 100644 --- a/src/components/Map/usePostsEngine.js +++ b/src/components/Map/usePostsEngine.js @@ -90,8 +90,8 @@ function filterByBounds(posts, map) { const ne = bounds.getNorthEast(); if (!sw || !ne) return posts; - const padLat = Math.abs(ne.lat - sw.lat) * 0.35; - const padLon = Math.abs(ne.lng - sw.lng) * 0.35; + const padLat = Math.abs(ne.lat - sw.lat) * 0.15; + const padLon = Math.abs(ne.lng - sw.lng) * 0.15; const minLat = sw.lat - padLat; const maxLat = ne.lat + padLat; const minLon = sw.lng - padLon; @@ -105,19 +105,6 @@ function filterByBounds(posts, map) { }); } -function filterByRadius(posts, center, radiusKm) { - if (!Array.isArray(posts) || posts.length === 0) return posts || []; - const [centerLon, centerLat] = center || []; - if (!Number.isFinite(centerLat) || !Number.isFinite(centerLon)) return posts || []; - const limit = Math.max(radiusKm || 0, 1); - return posts.filter((p) => { - const coords = getCoords(p); - if (!coords) return false; - const [lon, lat] = coords; - const dKm = haversineKm(centerLat, centerLon, lat, lon); - return dKm <= limit; - }); -} function getPostTimeMs(p) { const raw = p?.created_at || p?.CreatedAt || p?.createdAt || p?.published_at; @@ -533,14 +520,7 @@ export function usePostsEngine({ (tf) => { const vAll = computeVisible(tf); const map = mapRef.current; - let vBounded = filterByBounds(vAll, map); - if (vBounded.length === 0 && viewParams?.center && viewParams?.radiusKm) { - vBounded = filterByRadius(vAll, viewParams.center, viewParams.radiusKm * 1.2); - } - if (vBounded.length === 0) { - vBounded = vAll; - } - let v = vBounded; + let v = filterByBounds(vAll, map); if (v.length > MAX_VISIBLE_POSTS) { const center = map?.getCenter?.(); v = prunePosts(v, [center?.lng, center?.lat], MAX_VISIBLE_POSTS);