From 9680fb6a68193a5d6e4334ce3cd8664e5a6c1e71 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Fri, 9 Jan 2026 04:06:37 +0000 Subject: [PATCH] Add reverse geocoding lookup and display --- public-report/template/component/map-header.html | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/public-report/template/component/map-header.html b/public-report/template/component/map-header.html index 1b390b5a..740e17fa 100644 --- a/public-report/template/component/map-header.html +++ b/public-report/template/component/map-header.html @@ -25,6 +25,7 @@ function onMapMarkerDragEnd(marker) { return function() { const lngLat = marker.getLngLat(); displaySelectedCoordinates(lngLat); + reverseGeocode(lngLat); } } function displaySelectedCoordinates(lngLat) { @@ -33,6 +34,19 @@ function displaySelectedCoordinates(lngLat) { longitude.textContent = lngLat.lng; latitude.textContent = lngLat.lat; } +async function reverseGeocode(lngLat) { + const MAPBOX_ACCESS_TOKEN = '{{.MapboxToken}}'; + const url = `https://api.mapbox.com/search/geocode/v6/reverse?longitude=${lngLat.lng}&latitude=${lngLat.lat}&access_token=${MAPBOX_ACCESS_TOKEN}` + const response = await fetch(url); + const data = await response.json(); + console.log("reverse geocoded to", data); + if (data.features.length == 0) { + console.warn("No results for reverse geocode"); + return; + } + const match = data.features[0]; + displaySelectedLocation(match); +} function onLoadMap() { const MAPBOX_ACCESS_TOKEN = '{{.MapboxToken}}'; console.log("Setting up the map...");