From f52577151304033485d0390e620309e659bb61d7 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Thu, 25 Sep 2025 19:04:59 -0400 Subject: [PATCH 1/2] Export NSEW degrees text creation as its own function. --- src/mapbox.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/mapbox.ts b/src/mapbox.ts index c7773e3b..8ec52e46 100644 --- a/src/mapbox.ts +++ b/src/mapbox.ts @@ -188,6 +188,20 @@ function searchParams(options: MapBoxForwardGeocodingOptions | MapBoxReverseGeoc return search; } +/** + * Obtain a string describing the given location in terms of NSEW directions - for example: 10° N, 25° W + * @param longitudeDeg The longitude of the location, in degrees + * @param latitudeDeg The latitude of the location, in degrees + * @returns A string describing the given coordinates + */ +export function latitudeLongitudeText(longitudeDeg: number, latitudeDeg: number) { + const ns = latitudeDeg >= 0 ? 'N' : 'S'; + const ew = longitudeDeg >= 0 ? 'E' : 'W'; + const lat = Math.abs(latitudeDeg).toFixed(3); + const lon = Math.abs(longitudeDeg).toFixed(3); + return `${lat}° ${ns}, ${lon}° ${ew}`; +} + /** * Obtain text describing a given longitude and latitude based on a MapBox reverse geocoding query * @param longitudeDeg The longitude of the location, in degrees @@ -202,11 +216,7 @@ export async function textForLocation(longitudeDeg: number, latitudeDeg: number, .then(response => response.json()) .then((result: MapBoxFeatureCollection) => { if (result.features.length === 0) { - const ns = latitudeDeg >= 0 ? 'N' : 'S'; - const ew = longitudeDeg >= 0 ? 'E' : 'W'; - const lat = Math.abs(latitudeDeg).toFixed(3); - const lon = Math.abs(longitudeDeg).toFixed(3); - return `${lat}° ${ns}, ${lon}° ${ew}`; + return latitudeLongitudeText(latitudeDeg, longitudeDeg); } return textForMapboxResults(result); }); From f1765f846096936126ec2baf61bdbfed05fd781b Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Thu, 25 Sep 2025 19:10:19 -0400 Subject: [PATCH 2/2] Add return type annotation. --- src/mapbox.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mapbox.ts b/src/mapbox.ts index 8ec52e46..da30e4f9 100644 --- a/src/mapbox.ts +++ b/src/mapbox.ts @@ -194,7 +194,7 @@ function searchParams(options: MapBoxForwardGeocodingOptions | MapBoxReverseGeoc * @param latitudeDeg The latitude of the location, in degrees * @returns A string describing the given coordinates */ -export function latitudeLongitudeText(longitudeDeg: number, latitudeDeg: number) { +export function latitudeLongitudeText(longitudeDeg: number, latitudeDeg: number): string { const ns = latitudeDeg >= 0 ? 'N' : 'S'; const ew = longitudeDeg >= 0 ? 'E' : 'W'; const lat = Math.abs(latitudeDeg).toFixed(3);