From f7fc707159e500fcf76566e54fbcb41a18f84820 Mon Sep 17 00:00:00 2001 From: Deeptanshu Sankhwar Date: Tue, 11 Feb 2025 04:50:07 -0700 Subject: [PATCH] Show both lat/lon and lon/lat when searching coordinates (#10725) --- CHANGELOG.md | 3 +++ modules/ui/feature_list.js | 34 ++++++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4f4764d1..0db3452c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ _Breaking developer changes, which may affect downstream projects or sites that # Unreleased (2.32.0-dev) #### :sparkles: Usability & Accessibility +* Also show search result for coordinates in `lon/lat` order in search results ([#10720], thanks [@Deeptanshu-sankhwar]) #### :scissors: Operations #### :camera: Street-Level #### :white_check_mark: Validation @@ -54,9 +55,11 @@ _Breaking developer changes, which may affect downstream projects or sites that #### :hammer: Development [#10003]: https://github.com/openstreetmap/iD/pull/10003 +[#10720]: https://github.com/openstreetmap/iD/issues/10720 [#10747]: https://github.com/openstreetmap/iD/issues/10747 [#10748]: https://github.com/openstreetmap/iD/issues/10748 [@hlfan]: https://github.com/hlfan +[@Deeptanshu-sankhwar]: https://github.com/Deeptanshu-sankhwar # 2.31.1 diff --git a/modules/ui/feature_list.js b/modules/ui/feature_list.js index 9e8a3df46..19c778e51 100644 --- a/modules/ui/feature_list.js +++ b/modules/ui/feature_list.js @@ -127,14 +127,32 @@ export function uiFeatureList(context) { var locationMatch = sexagesimal.pair(q.toUpperCase()) || dmsMatcher(q); if (locationMatch) { - var loc = [Number(locationMatch[0]), Number(locationMatch[1])]; - result.push({ - id: loc[0] + '/' + loc[1], - geometry: 'point', - type: t('inspector.location'), - name: dmsCoordinatePair([loc[1], loc[0]]), - location: loc - }); + const latLon = [Number(locationMatch[0]), Number(locationMatch[1])]; + const lonLat = [latLon[1], latLon[0]]; // also try swapped order + + const isLatLonValid = latLon[0] >= -90 && latLon[0] <= 90 && latLon[1] >= -180 && latLon[1] <= 180; + let isLonLatValid = lonLat[0] >= -90 && lonLat[0] <= 90 && lonLat[1] >= -180 && lonLat[1] <= 180; + isLonLatValid &&= !q.match(/[NSEW]/i); + isLonLatValid &&= lonLat[0] !== lonLat[1]; + + if (isLatLonValid) { + result.push({ + id: latLon[0] + '/' + latLon[1], + geometry: 'point', + type: t('inspector.location'), + name: dmsCoordinatePair([latLon[1], latLon[0]]), + location: latLon + }); + } + if (isLonLatValid) { + result.push({ + id: lonLat[0] + '/' + lonLat[1], + geometry: 'point', + type: t('inspector.location'), + name: dmsCoordinatePair([lonLat[1], lonLat[0]]), + location: lonLat + }); + } } // A location search takes priority over an ID search