diff --git a/html/template/rmo/nuisance.html b/html/template/rmo/nuisance.html index c79e982d..eed8f5e3 100644 --- a/html/template/rmo/nuisance.html +++ b/html/template/rmo/nuisance.html @@ -38,48 +38,6 @@ setLocationInputs(response.features[0]); } } - function setLocationInputs(location) { - let country = document.getElementById("address-country"); - let latitude = document.getElementById("latitude"); - let longitude = document.getElementById("longitude"); - let latlngAccuracyType = document.getElementById("latlng-accuracy-type"); - let latlngAccuracyValue = document.getElementById( - "latlng-accuracy-value", - ); - let number = document.getElementById("address-number"); - let postalcode = document.getElementById("address-postalcode"); - let locality = document.getElementById("address-locality"); - let region = document.getElementById("address-region"); - let street = document.getElementById("address-street"); - - // Extract context data from properties - const props = location.properties; - const context = props.context || {}; - - // Populate structured fields - country.value = context.iso_3166_a3; - latitude.value = location.geometry.coordinates[1]; - longitude.value = location.geometry.coordinates[0]; - latlngAccuracyType.value = props.precision; - latlngAccuracyValue.value = props.distance; - number.value = props.address_components?.number ?? ""; - postalcode.value = props.address_components?.postal_code ?? ""; - locality.value = context.whosonfirst?.locality?.name ?? ""; - region.value = context.whosonfirst?.region?.abbreviation ?? ""; - street.value = props.address_components?.street ?? ""; - } - function toggleCollapse(something) { - el = document.getElementById(something); - if (el.classList.contains("collapse")) { - el.classList.remove("collapse"); - } else { - el.classList.add("collapse"); - } - document - .getElementById("toggle-additional") - .classList.add("visually-hidden"); - } - // Check for source identification document.addEventListener("DOMContentLoaded", function () { // Elements diff --git a/ts/components/AddressSuggestion.vue b/ts/components/AddressSuggestion.vue index 2aa662b9..8770f10a 100644 --- a/ts/components/AddressSuggestion.vue +++ b/ts/components/AddressSuggestion.vue @@ -49,6 +49,7 @@
- - - - - - - - - - -
@@ -591,6 +563,51 @@ async function doSubmit() { errorMessage.value = ""; try { const formData = new FormData(formElement.value); + if (selectedAddress.value) { + const address = selectedAddress.value; + const props = address.properties; + const context = props.context || {}; + + formData.append("address-country", context.iso_3166_a3); + formData.append( + "address-locality", + context.whosonfirst?.locality?.name ?? "", + ); + formData.append("address-number", props.address_components?.number ?? ""); + formData.append( + "address-postalcode", + props.address_components?.postal_code ?? "", + ); + formData.append( + "address-region", + context.whosonfirst?.region?.abbreviation ?? "", + ); + formData.append("address-street", props.address_components?.street ?? ""); + formData.append( + "latitude", + address.geometry?.coordinates[1].toString() ?? "0", + ); + formData.append( + "longitude", + address.geometry?.coordinates[0].toString() ?? "0", + ); + formData.append("latlng-accuracy-type", props.precision ?? ""); + formData.append( + "latlng-accuracy-value", + props.distance?.toString() ?? "", + ); + } else { + formData.append("address-country", ""); + formData.append("address-locality", ""); + formData.append("address-number", ""); + formData.append("address-postalcode", ""); + formData.append("address-region", ""); + formData.append("address-street", ""); + formData.append("latitude", "0"); + formData.append("longitude", "0"); + formData.append("latlng-accuracy-type", ""); + formData.append("latlng-accuracy-value", ""); + } images.value.forEach((image, index) => { formData.append(`image[${index}]`, image.file, image.name); }); diff --git a/ts/type/stadia.ts b/ts/type/stadia.ts index 9fc96cef..590133c0 100644 --- a/ts/type/stadia.ts +++ b/ts/type/stadia.ts @@ -1,22 +1,39 @@ // Interface definitions interface AddressComponents { number?: string; + postal_code?: string; street?: string; - city?: string; - state?: string; - zip?: string; } +interface AddressContext { + iso_3166_a2: string; // "US" + iso_3166_a3: string; // "USA" + whosonfirst?: AddressContextWhosOnFirst; +} +interface AddressContextWhosOnFirst { + country: WhosOnFirstEntry; + county: WhosOnFirstEntry; + locality: WhosOnFirstEntry; + region: WhosOnFirstEntry; +} +interface WhosOnFirstEntry { + abbreviation?: string; // "SL" or "UT" + gid: string; // "whosonfirst:county:102082877" + name: string; // "Salt Lake County" +} interface AddressProperties { - gid: string; - name: string; - coarse_location?: string; - formatted_address_line?: string; address_components?: AddressComponents; + coarse_location?: string; + context: AddressContext; coordinates?: { lat: number; lon: number; }; + distance?: number; + formatted_address_line?: string; + gid: string; + precision?: string; // "centroid" + name: string; } export interface Address {