Add out of bounds fetching

This commit is contained in:
Andras Schmelczer 2026-01-26 21:30:35 +00:00
parent c85fe82e24
commit 8a8df2ebfa
2 changed files with 16 additions and 0 deletions

View file

@ -12,6 +12,10 @@ from pipeline.config import (
DEFAULT_MAX_PRICE,
)
# Extra area to return beyond requested bounds (0.2 = 20%)
# Makes panning smoother by preloading nearby hexagons
BOUNDS_BUFFER_PERCENT = 0.2
__all__ = [
"AGGREGATES_DIR",
"VALID_RESOLUTIONS",
@ -22,4 +26,5 @@ __all__ = [
"DEFAULT_MAX_YEAR",
"DEFAULT_MIN_PRICE",
"DEFAULT_MAX_PRICE",
"BOUNDS_BUFFER_PERCENT",
]

View file

@ -14,6 +14,7 @@ from server.config import (
DEFAULT_MAX_YEAR,
DEFAULT_MIN_PRICE,
DEFAULT_MAX_PRICE,
BOUNDS_BUFFER_PERCENT,
)
router = APIRouter()
@ -138,6 +139,16 @@ async def get_hexagons(
status_code=400, detail="Invalid bounds format. Use: south,west,north,east"
)
# Expand bounds by buffer percentage for smoother panning
lat_range = north - south
lng_range = east - west
lat_buffer = lat_range * BOUNDS_BUFFER_PERCENT
lng_buffer = lng_range * BOUNDS_BUFFER_PERCENT
south -= lat_buffer
north += lat_buffer
west -= lng_buffer
east += lng_buffer
# Round bounds to reduce cache misses (0.01 degree ≈ 1km precision)
# Always expand bounds (floor for min, ceil for max) to prevent hexagons
# popping in when crossing rounding boundaries