mirror of
https://github.com/zvx-echo6/recon.git
synced 2026-05-20 06:34:40 +02:00
feat(geocode): add viewport bias for location-aware search
- Add lat/lon/zoom params to geocode() and _retrieve_photon_freetext() - Update nav_tools.py wrapper to pass through viewport params - Add /api/geocode handler support for lat/lon/zoom query params - Add _safe_float() helper for param validation - Cast zoom to int for Photon compatibility Allows the frontend to pass current map center/zoom to bias search results toward the visible area. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
f35af18320
commit
2ed9335f4e
3 changed files with 29 additions and 12 deletions
|
|
@ -35,6 +35,19 @@ def api_netsyms_health():
|
|||
return jsonify(netsyms.health())
|
||||
|
||||
|
||||
|
||||
def _safe_float(val, lo, hi):
|
||||
"""Parse val as float; return None if missing, non-numeric, or out of [lo, hi]."""
|
||||
if val is None:
|
||||
return None
|
||||
try:
|
||||
f = float(val)
|
||||
if lo <= f <= hi:
|
||||
return f
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
return None
|
||||
|
||||
@geocode_bp.route('/api/geocode')
|
||||
def api_geocode():
|
||||
"""
|
||||
|
|
@ -58,7 +71,12 @@ def api_geocode():
|
|||
except (ValueError, TypeError):
|
||||
limit = 10
|
||||
|
||||
result = nav_tools.geocode(q, limit=limit)
|
||||
# Viewport bias parameters (optional)
|
||||
lat = _safe_float(request.args.get("lat"), -90, 90)
|
||||
lon = _safe_float(request.args.get("lon"), -180, 180)
|
||||
zoom = _safe_float(request.args.get("zoom"), 0, 22)
|
||||
|
||||
result = nav_tools.geocode(q, limit=limit, lat=lat, lon=lon, zoom=zoom)
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue