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