Relax map bounds filter and add radius fallback
This commit is contained in:
parent
92e9cfc566
commit
68cb21fc23
|
|
@ -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.12;
|
const padLat = Math.abs(ne.lat - sw.lat) * 0.35;
|
||||||
const padLon = Math.abs(ne.lng - sw.lng) * 0.12;
|
const padLon = Math.abs(ne.lng - sw.lng) * 0.35;
|
||||||
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,6 +105,20 @@ 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;
|
||||||
if (!raw) return 0;
|
if (!raw) return 0;
|
||||||
|
|
@ -519,7 +533,10 @@ export function usePostsEngine({
|
||||||
(tf) => {
|
(tf) => {
|
||||||
const vAll = computeVisible(tf);
|
const vAll = computeVisible(tf);
|
||||||
const map = mapRef.current;
|
const map = mapRef.current;
|
||||||
const vBounded = filterByBounds(vAll, map);
|
let vBounded = filterByBounds(vAll, map);
|
||||||
|
if (vBounded.length === 0 && viewParams?.center && viewParams?.radiusKm) {
|
||||||
|
vBounded = filterByRadius(vAll, viewParams.center, viewParams.radiusKm * 1.2);
|
||||||
|
}
|
||||||
let v = vBounded;
|
let v = vBounded;
|
||||||
if (v.length > MAX_VISIBLE_POSTS) {
|
if (v.length > MAX_VISIBLE_POSTS) {
|
||||||
const center = map?.getCenter?.();
|
const center = map?.getCenter?.();
|
||||||
|
|
@ -552,7 +569,7 @@ export function usePostsEngine({
|
||||||
|
|
||||||
syncMarkers(v);
|
syncMarkers(v);
|
||||||
},
|
},
|
||||||
[computeVisible, syncMarkers, mapRef, ensureClusterLayers, updateClusterData, setClusterVisibility, splitForClusters, syncPriorityMarkers]
|
[computeVisible, syncMarkers, mapRef, ensureClusterLayers, updateClusterData, setClusterVisibility, splitForClusters, syncPriorityMarkers, viewParams]
|
||||||
);
|
);
|
||||||
|
|
||||||
// On filter/search changes: recompute + sync (NO clear-all rebuild)
|
// On filter/search changes: recompute + sync (NO clear-all rebuild)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue