Restrict map to bounds-only posts

This commit is contained in:
Your Name 2025-12-26 01:48:59 -05:00
parent d7bf3e22cb
commit 2eb182fccc
1 changed files with 3 additions and 23 deletions

View File

@ -90,8 +90,8 @@ function filterByBounds(posts, map) {
const ne = bounds.getNorthEast(); const ne = bounds.getNorthEast();
if (!sw || !ne) return posts; if (!sw || !ne) return posts;
const padLat = Math.abs(ne.lat - sw.lat) * 0.35; const padLat = Math.abs(ne.lat - sw.lat) * 0.15;
const padLon = Math.abs(ne.lng - sw.lng) * 0.35; const padLon = Math.abs(ne.lng - sw.lng) * 0.15;
const minLat = sw.lat - padLat; const minLat = sw.lat - padLat;
const maxLat = ne.lat + padLat; const maxLat = ne.lat + padLat;
const minLon = sw.lng - padLon; 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) { function getPostTimeMs(p) {
const raw = p?.created_at || p?.CreatedAt || p?.createdAt || p?.published_at; const raw = p?.created_at || p?.CreatedAt || p?.createdAt || p?.published_at;
@ -533,14 +520,7 @@ export function usePostsEngine({
(tf) => { (tf) => {
const vAll = computeVisible(tf); const vAll = computeVisible(tf);
const map = mapRef.current; const map = mapRef.current;
let vBounded = filterByBounds(vAll, map); let v = 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;
if (v.length > MAX_VISIBLE_POSTS) { if (v.length > MAX_VISIBLE_POSTS) {
const center = map?.getCenter?.(); const center = map?.getCenter?.();
v = prunePosts(v, [center?.lng, center?.lat], MAX_VISIBLE_POSTS); v = prunePosts(v, [center?.lng, center?.lat], MAX_VISIBLE_POSTS);