Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DT-6017 Support reverse geocoding in additional countries #4845

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 Expand Up @@ -176,7 +186,7 @@
if (permissionStatus.state === 'prompt') {
// track when user allows geolocation
/* eslint-disable no-param-reassign */
permissionStatus.onchange = function () {

Check warning on line 189 in app/action/PositionActions.js

View workflow job for this annotation

GitHub Actions / lint (12.x)

Unexpected unnamed function
if (this.state === 'granted') {
addAnalyticsEvent({
category: 'Map',
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
Loading