From 1bf817d676df9c4fcd3f90a4dfef0ecaee9be401 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Mon, 31 Jul 2023 14:56:55 +0300 Subject: [PATCH] feat: support additional countries in reverse geocoding --- app/action/PositionActions.js | 14 +++++- app/component/ParkOrStationHeader.js | 10 ++++- app/component/StopCardHeader.js | 53 +++++++++++++---------- app/component/map/SelectFromMap.js | 12 ++++- app/component/map/popups/LocationPopup.js | 10 ++++- 5 files changed, 69 insertions(+), 30 deletions(-) diff --git a/app/action/PositionActions.js b/app/action/PositionActions.js index d03cc6cb85..dbd8977fff 100644 --- a/app/action/PositionActions.js +++ b/app/action/PositionActions.js @@ -11,13 +11,23 @@ let geoWatchId; function reverseGeocodeAddress(actionContext, location) { const language = actionContext.getStore('PreferencesStore').getLanguage(); - return getJson(actionContext.config.URL.PELIAS_REVERSE_GEOCODER, { + const searchParams = { 'point.lat': location.lat, 'point.lon': location.lon, lang: language, size: 1, layers: 'address', - }).then(data => { + }; + + if (actionContext.config.searchParams['boundary.country']) { + searchParams['boundary.country'] = + actionContext.config.searchParams['boundary.country']; + } + + return getJson( + actionContext.config.URL.PELIAS_REVERSE_GEOCODER, + searchParams, + ).then(data => { if (data.features != null && data.features.length > 0) { const match = data.features[0].properties; actionContext.dispatch('AddressFound', { diff --git a/app/component/ParkOrStationHeader.js b/app/component/ParkOrStationHeader.js index bd85d5bd0d..cca93020f5 100644 --- a/app/component/ParkOrStationHeader.js +++ b/app/component/ParkOrStationHeader.js @@ -17,14 +17,20 @@ const modules = { const ParkOrBikeStationHeader = ({ parkOrStation, breakpoint }, { config }) => { const [zoneId, setZoneId] = useState(undefined); useEffect(() => { - getJson(config.URL.PELIAS_REVERSE_GEOCODER, { + const searchParams = { 'point.lat': parkOrStation.lat, 'point.lon': parkOrStation.lon, 'boundary.circle.radius': 0.2, layers: 'address', size: 1, zones: 1, - }).then(data => { + }; + if (config.searchParams['boundary.country']) { + searchParams['boundary.country'] = + config.searchParams['boundary.country']; + } + + getJson(config.URL.PELIAS_REVERSE_GEOCODER, searchParams).then(data => { if (data.features != null && data.features.length > 0) { const match = data.features[0].properties; const id = getZoneId(config, match.zones, data.zones); diff --git a/app/component/StopCardHeader.js b/app/component/StopCardHeader.js index 733dec29f3..92d51a7c94 100644 --- a/app/component/StopCardHeader.js +++ b/app/component/StopCardHeader.js @@ -27,33 +27,42 @@ class StopCardHeader extends React.Component { name = `${name} ${stop.code}`; } - getJson(this.context.config.URL.PELIAS_REVERSE_GEOCODER, { + const searchParams = { 'point.lat': stop.lat, 'point.lon': stop.lon, 'boundary.circle.radius': 0.2, size: 1, - }).then(data => { - if (data.features != null && data.features.length > 0) { - const match = data.features[0].properties; - const city = match.localadmin; - - this.context.executeAction(saveSearch, { - item: { - geometry: { coordinates: [stop.lon, stop.lat] }, - properties: { - name, - id, - gid: `gtfs:${layer}:${id}`, - layer, - label: `${stop.name}, ${city}`, - localadmin: city, + }; + if (this.context.config.searchParams['boundary.country']) { + searchParams['boundary.country'] = this.context.config.searchParams[ + 'boundary.country' + ]; + } + + getJson(this.context.config.URL.PELIAS_REVERSE_GEOCODER, searchParams).then( + data => { + if (data.features != null && data.features.length > 0) { + const match = data.features[0].properties; + const city = match.localadmin; + + this.context.executeAction(saveSearch, { + item: { + geometry: { coordinates: [stop.lon, stop.lat] }, + properties: { + name, + id, + gid: `gtfs:${layer}:${id}`, + layer, + label: `${stop.name}, ${city}`, + localadmin: city, + }, + type: 'Feature', }, - type: 'Feature', - }, - type: 'endpoint', - }); - } - }); + type: 'endpoint', + }); + } + }, + ); } get headerConfig() { diff --git a/app/component/map/SelectFromMap.js b/app/component/map/SelectFromMap.js index f96f7a820b..c722bcf1f4 100644 --- a/app/component/map/SelectFromMap.js +++ b/app/component/map/SelectFromMap.js @@ -59,7 +59,8 @@ class SelectFromMapPageMap extends React.Component { setAddress = (lat, lon) => { const { intl } = this.context; - getJson(this.context.config.URL.PELIAS_REVERSE_GEOCODER, { + + const searchParams = { 'point.lat': lat, 'point.lon': lon, 'boundary.circle.radius': 0.1, // 100m @@ -67,7 +68,14 @@ class SelectFromMapPageMap extends React.Component { size: 1, layers: 'address', zones: 1, - }).then( + }; + if (this.context.config.searchParams['boundary.country']) { + searchParams['boundary.country'] = this.context.config.searchParams[ + 'boundary.country' + ]; + } + + getJson(this.context.config.URL.PELIAS_REVERSE_GEOCODER, searchParams).then( data => { if (data.features != null && data.features.length > 0) { const match = data.features[0].properties; diff --git a/app/component/map/popups/LocationPopup.js b/app/component/map/popups/LocationPopup.js index ee8afa946b..99bd003c85 100644 --- a/app/component/map/popups/LocationPopup.js +++ b/app/component/map/popups/LocationPopup.js @@ -44,7 +44,7 @@ class LocationPopup extends React.Component { const { lat, lon } = this.props; const { config } = this.context; - getJson(config.URL.PELIAS_REVERSE_GEOCODER, { + const searchParams = { 'point.lat': lat, 'point.lon': lon, 'boundary.circle.radius': 0.1, // 100m @@ -52,7 +52,13 @@ class LocationPopup extends React.Component { size: 1, layers: 'address', zones: 1, - }).then( + }; + if (config.searchParams['boundary.country']) { + searchParams['boundary.country'] = + config.searchParams['boundary.country']; + } + + getJson(config.URL.PELIAS_REVERSE_GEOCODER, searchParams).then( data => { let pointName; if (data.features != null && data.features.length > 0) {