From a2b8527d918dc70e017d3066af5cd78ce321d2f1 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Mon, 27 Apr 2026 19:40:24 +0000 Subject: [PATCH] Track user location with map and address data This is useful because everywhere that we use the AddressAndMapLocator component we also want to use the user's location and we want to zoom the map based on their location. Instead of tracking this externally in 3 places we just pull it into the component. --- ts/rmo/components/AddressAndMapLocator.vue | 70 +++++++++++++++------- ts/rmo/content/Nuisance.vue | 57 +++++------------- ts/rmo/content/Water.vue | 37 ++++++------ ts/rmo/content/compliance/Address.vue | 16 +++-- ts/store/geocode.ts | 12 +++- ts/type/map.ts | 11 ++++ 6 files changed, 113 insertions(+), 90 deletions(-) diff --git a/ts/rmo/components/AddressAndMapLocator.vue b/ts/rmo/components/AddressAndMapLocator.vue index 8f8a91f2..0fd964f3 100644 --- a/ts/rmo/components/AddressAndMapLocator.vue +++ b/ts/rmo/components/AddressAndMapLocator.vue @@ -38,7 +38,7 @@ diff --git a/ts/rmo/content/Nuisance.vue b/ts/rmo/content/Nuisance.vue index 91ec13b5..acf0c5e7 100644 --- a/ts/rmo/content/Nuisance.vue +++ b/ts/rmo/content/Nuisance.vue @@ -125,7 +125,7 @@ select.tall {

You can also click on the map to mark the location precisely

- +
@@ -470,21 +470,17 @@ import MapLocator from "@/components/MapLocator.vue"; import AddressAndMapLocator from "@/rmo/components/AddressAndMapLocator.vue"; import { useStoreGeocode } from "@/store/geocode"; import { useStoreLocal } from "@/store/local"; -import { useStoreLocation } from "@/store/location"; import { useStorePublicReport } from "@/store/publicreport"; import type { Marker } from "@/types"; import { - Address, type Geocode, type GeocodeSuggestion, - type Location, type PublicReport, } from "@/type/api"; +import { Locator } from "@/type/map"; import type { Camera } from "@/type/map"; -const address = ref
(new Address()); -const currentCamera = ref(null); -const currentLocation = ref(null); +const locator = ref(new Locator()); const errorMessage = ref(""); const formElement = ref(null); const images = ref([]); @@ -492,7 +488,6 @@ const isSubmitting = ref(false); const showMore = ref(false); const storeLocal = useStoreLocal(); -const storeLocation = useStoreLocation(); const storePublicReport = useStorePublicReport(); const geocode = useStoreGeocode(); const router = useRouter(); @@ -504,32 +499,28 @@ async function doSubmit() { try { const client_id = storeLocal.getClientID(); const formData = new FormData(formElement.value); + formData.append("address.gid", locator.value.address.gid); + formData.append("address.raw", locator.value.address.raw); + formData.append( + "address.location.latitude", + locator.value.address.location?.latitude?.toString() ?? "0", + ); + formData.append( + "address.location.longitude", + locator.value.address.location?.longitude?.toString() ?? "0", + ); formData.append("client_id", client_id); - if (address.value) { - formData.append("address.gid", address.value.gid); - formData.append("address.raw", address.value.raw); - if (address.value.location) { - formData.append( - "address.location.latitude", - address.value.location.latitude.toString(), - ); - formData.append( - "address.location.longitude", - address.value.location.longitude.toString(), - ); - } - } formData.append( "location.accuracy", - currentLocation.value?.accuracy?.toString() ?? "0", + locator.value.location.accuracy?.toString() ?? "0", ); formData.append( "location.latitude", - currentLocation.value?.latitude.toString() ?? "0", + locator.value.location.latitude?.toString() ?? "0", ); formData.append( "location.longitude", - currentLocation.value?.longitude.toString() ?? "0", + locator.value.location.longitude?.toString() ?? "0", ); images.value.forEach((image, index) => { formData.append(`image[${index}]`, image.file, image.name); @@ -549,20 +540,4 @@ async function doSubmit() { isSubmitting.value = false; } } -onMounted(() => { - storeLocation - .get() - .then((loc: GeolocationPosition) => { - console.log("user geolocation", loc); - const coords = loc.coords; - currentLocation.value = coords; - currentCamera.value = { - location: coords, - zoom: 15, - }; - }) - .catch((e) => { - console.log("failed to get location", e); - }); -}); diff --git a/ts/rmo/content/Water.vue b/ts/rmo/content/Water.vue index b1d17620..c6875329 100644 --- a/ts/rmo/content/Water.vue +++ b/ts/rmo/content/Water.vue @@ -210,7 +210,7 @@ select.tall {

You can also click on the map to mark the location precisely

- +