# file: map_utils.py import json import gradio as gr # <-- Add this import from api_clients import AVAILABLE_BASEMAPS def render_map_html_structure(geojson_str: str): # ... (this function is unchanged) ... if not geojson_str: return "
Run a query to display the map.
" return '
' def get_map_init_script(basemap_name: str, geojson_str: str) -> str: # ... (this function is unchanged) ... if not basemap_name or not geojson_str: return "" basemap_info = AVAILABLE_BASEMAPS.get(basemap_name) if not basemap_info: return "alert('Basemap not found!');" native_zoom = basemap_info.get("native_zoom", 16) parcel_json_str = json.dumps(json.loads(geojson_str)) return f""" var container = L.DomUtil.get('map'); if(container != null){{ container._leaflet_id = null; }} var map = L.map('map').setView([47.4, -122.5], 9); L.tileLayer('{basemap_info['url']}', {{ maxZoom: 22, maxNativeZoom: {native_zoom}, attribution: '{basemap_info['attribution']}' }}).addTo(map); var p_data = {parcel_json_str}; if (p_data && p_data.type) {{ var p_layer = L.geoJSON(p_data, {{ style: () => ({{ color: "#e60000", weight: 3, opacity: 0.9, fillColor: "#e60000", fillOpacity: 0.2 }}) }}).addTo(map); map.fitBounds(p_layer.getBounds().pad(0.1), {{ maxZoom: 19 }}); }} """ def handle_map_type_change(basemap_name, geojson_str): new_html = render_map_html_structure(geojson_str) new_script = get_map_init_script(basemap_name, geojson_str) # --- THIS IS THE FIX --- # Return two gr.update objects directly, not dictionaries. return gr.update(value=new_html), gr.update(value=new_script)