Skip to content

Commit

Permalink
Merge pull request #4845 from HSLdevcom/fix-reverse
Browse files Browse the repository at this point in the history
DT-6017 Support reverse geocoding in additional countries
  • Loading branch information
Antiik91 authored Aug 1, 2023
2 parents 5357913 + 1bf817d commit 0bb9560
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 30 deletions.
14 changes: 12 additions & 2 deletions app/action/PositionActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
10 changes: 8 additions & 2 deletions app/component/ParkOrStationHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
53 changes: 31 additions & 22 deletions app/component/StopCardHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
12 changes: 10 additions & 2 deletions app/component/map/SelectFromMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,23 @@ 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
lang: this.props.language,
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;
Expand Down
10 changes: 8 additions & 2 deletions app/component/map/popups/LocationPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,21 @@ 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
lang: this.props.language,
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) {
Expand Down

0 comments on commit 0bb9560

Please sign in to comment.