From 8a8df2ebfac48c4f3afdcde15b6fda3873bbdba1 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Mon, 26 Jan 2026 21:30:35 +0000 Subject: [PATCH] Add out of bounds fetching --- server/config.py | 5 +++++ server/routes/hexagons.py | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/server/config.py b/server/config.py index dfc1f00..798a6bd 100644 --- a/server/config.py +++ b/server/config.py @@ -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", ] diff --git a/server/routes/hexagons.py b/server/routes/hexagons.py index b4cc24f..987c749 100644 --- a/server/routes/hexagons.py +++ b/server/routes/hexagons.py @@ -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