Skip to content

Commit

Permalink
test pos action changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vesameskanen committed Feb 5, 2025
1 parent b78ad12 commit ba993e8
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions app/action/PositionActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,31 @@ function reverseGeocodeAddress(actionContext, coords) {
searchParams['boundary.country'] =
actionContext.config.searchParams['boundary.country'];
}
actionContext.dispatch('StartReverseGeocoding');

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', {
address: match.name,
gid: match.gid,
name: match.name,
layer: match.layer,
city: match.localadmin || match.locality,
});
} else {
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', {
address: match.name,
gid: match.gid,
name: match.name,
layer: match.layer,
city: match.localadmin || match.locality,
});
} else {
actionContext.dispatch('AddressFound', {});
}
})
.catch(() => {
actionContext.dispatch('AddressFound', {});
}
});
});
}

const debouncedReverseGeocoding = debounce(reverseGeocodeAddress, 10000, {
const runReverseGeocodingAction = (actionContext, coords) =>
actionContext.executeAction(reverseGeocodeAddress, coords);

const debouncedReverseGeocoding = debounce(runReverseGeocodingAction, 10000, {
leading: true,
});

Expand Down

0 comments on commit ba993e8

Please sign in to comment.