Include address information on nuisance form upload

This commit is contained in:
Eli Ribble 2026-04-03 23:04:04 +00:00
parent e08f614d11
commit e56e83161b
No known key found for this signature in database
4 changed files with 70 additions and 77 deletions

View file

@ -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

View file

@ -49,6 +49,7 @@
<div class="address-input-wrapper">
<label for="addressInput" class="form-label">Enter address</label>
<input
autocomplete="off"
id="addressInput"
v-model="searchText"
class="form-control"

View file

@ -163,34 +163,6 @@ select.tall {
@marker-drag-end="doMapMarkerDragEnd"
/>
</div>
<input
type="hidden"
id="map-zoom"
name="map-zoom"
:value="currentCamera?.zoom ?? 0"
/>
<input type="hidden" id="address-country" name="address-country" />
<input type="hidden" id="address-locality" name="address-locality" />
<input type="hidden" id="address-number" name="address-number" />
<input
type="hidden"
id="address-postalcode"
name="address-postalcode"
/>
<input type="hidden" id="address-region" name="address-region" />
<input type="hidden" id="address-street" name="address-street" />
<input type="hidden" id="latitude" name="latitude" />
<input type="hidden" id="longitude" name="longitude" />
<input
type="hidden"
id="latlng-accuracy-type"
name="latlng-accuracy-type"
/>
<input
type="hidden"
id="latlng-accuracy-value"
name="latlng-accuracy-value"
/>
<!-- Mosquito Activity Section -->
<div class="form-section">
@ -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);
});

View file

@ -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 {