Skip to content

Commit

Permalink
rework geocode with pelias endpoints
Browse files Browse the repository at this point in the history
geocoding requests now are sent to host/geocode/search? and host/geocode/reverse? enpoints
instead of host/geocode.

Functionality is the same as before.
Additionally the center of the current map view is used as a focus point by default.
Objects within 100km of this point are more relevant. Importance decays from the center outward.
Overall accuracy should be enhanced with this.

closes #196
  • Loading branch information
TheGreatRefrigerator committed May 12, 2018
1 parent cb8848d commit 234cfb7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/components/ors-map/ors-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ angular.module('orsApp')
const latLngString = orsUtilsService.parseLatLngString(pos);
// get the information of the rightclick location
const payload = orsUtilsService.geocodingPayload(lngLatString, true);
const request = orsRequestService.geocode(payload);
const request = orsRequestService.geocode(payload, true);
request.promise.then((data) => {
$scope.address = {};
if (data.features.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,8 @@ angular.module('orsApp.ors-addresses', ['orsApp.ors-exportRoute-controls', 'focu
orsRequestService.geocodeRequests.updateRequest(request, ctrl.idx, 'routeRequests');
orsRequestService.requestSubject.onNext(true);
request.promise.then((data) => {
console.log(data.features.length)
console.log(data)
if (data.features.length > 0) {
ctrl.addresses = orsUtilsService.addShortAddresses(data.features);
console.log(ctrl.addresses)
if (ctrl.isDirections) {
orsRequestService.savedRequests.directions[ctrl.showGeocodingPanelIdx] = ctrl.addresses;
} else {
Expand All @@ -70,7 +67,6 @@ angular.module('orsApp.ors-addresses', ['orsApp.ors-exportRoute-controls', 'focu
orsRequestService.requestSubject.onNext(false);
}, (response) => {
// this will be caught my the httpinterceptor
console.log(response);
orsRequestService.requestSubject.onNext(false);
});
};
Expand Down
15 changes: 11 additions & 4 deletions app/infrastructure/ors-request-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ angular.module('orsApp.request-service', [])
* Replaces request if new one is fired on same index
* @param {Object} request: xhr request
* @param {number} idx: WP idx
* @param {string} panel: Current requests que
* @param {string} panel: Current requests queue
*/
orsRequestService.geocodeRequests.updateRequest = (request, idx, requestsQue) => {
if (typeof orsRequestService.geocodeRequests[requestsQue][idx] === 'undefined') {
Expand All @@ -32,9 +32,9 @@ angular.module('orsApp.request-service', [])
}
};
/**
* Removes requests from the que, used if waypoints are removed from list
* Removes requests from the queue, used if waypoints are removed from list
* @param {number} idx: WP idx
* @param {string} requestsQue: Current requests que
* @param {string} requestsQue: Current requests queue
*/
orsRequestService.geocodeRequests.removeRequest = (idx, requestsQue) => {
if (typeof orsRequestService.geocodeRequests[requestsQue][idx] !== 'undefined') {
Expand All @@ -55,8 +55,15 @@ angular.module('orsApp.request-service', [])
let action = orsObjectsFactory.createMapAction(0, lists.layers[0], geom, undefined);
orsMapFactory.mapServiceSubject.onNext(action);
};
orsRequestService.geocode = (requestData) => {
/**
*
* @param requestData -
* @param reverse - true for reverse geocoding request
* @returns {{promise: *, cancel: cancel}}
*/
orsRequestService.geocode = (requestData, reverse = false) => {
var url = ENV.geocoding;
reverse ? url += '/reverse' : url += '/search';
var canceller = $q.defer();
var cancel = function(reason) {
canceller.resolve(reason);
Expand Down
2 changes: 1 addition & 1 deletion app/infrastructure/ors-settings-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ angular.module('orsApp.settings-service', [])
const lngLatString = orsUtilsService.parseLngLatString(pos);
orsSettingsFactory.updateWaypointAddress(idx, latLngString, init);
const payload = orsUtilsService.geocodingPayload(lngLatString, true);
const request = orsRequestService.geocode(payload);
const request = orsRequestService.geocode(payload, true);
const requestsQue = orsSettingsFactory.ngRouteSubject.getValue() == 'directions' ? 'routeRequests' : 'aaRequests';
orsRequestService.geocodeRequests.updateRequest(request, idx, requestsQue);
request.promise.then((data) => {
Expand Down
31 changes: 18 additions & 13 deletions app/infrastructure/ors-utils-service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module('orsApp.utils-service', [])
.factory('orsUtilsService', ['$q', '$http', '$timeout', '$location', 'lists', 'mappings', 'ENV', ($q, $http, $timeout, $location, lists, mappings, ENV) => {
.factory('orsUtilsService', ['$q', '$http', '$timeout', '$location', '$injector', 'lists', 'mappings', 'ENV', ($q, $http, $timeout, $location, $injector, lists, mappings, ENV) => {
let orsUtilsService = {};
/**
* trims coordinates
Expand Down Expand Up @@ -209,19 +209,24 @@ angular.module('orsApp.utils-service', [])
* @param {number} limit: To limit the amount of responses
* @return {Object} payload: Paylod object used in xhr request
*/
orsUtilsService.geocodingPayload = function(obj, reverse = false, language = 'en', limit = 5) {
orsUtilsService.geocodingPayload = function(obj, reverse = false, language = 'en-US', limit = 5) {
let payload;
let orsSettingsFactory = $injector.get('orsSettingsFactory');
if (!reverse) {
payload = {
query: obj,
text: obj,
lang: language,
limit: limit
size: limit,
'focus.point.lat': orsSettingsFactory.getUserOptions().lat ,
'focus.point.lon': orsSettingsFactory.getUserOptions().lng
};
} else {
payload = {
location: obj,
'point.lat': obj.split(', ')[1],
'point.lon': obj.split(', ')[0],
// location: obj,
lang: language,
limit: 1
size: 1
};
}
return payload;
Expand Down Expand Up @@ -412,16 +417,16 @@ angular.module('orsApp.utils-service', [])
feature.processed.primary = properties.name;
if ('street' in properties) {
feature.processed.primary += ', ' + properties.street;
if ('house_number' in properties) {
feature.processed.primary += ' ' + properties.house_number;
if ('housenumber' in properties) {
feature.processed.primary += ' ' + properties.housenumber;
}
}
} else if ('street' in properties) {
const streetAddress = [];
// street and name can be the same, just needed once
streetAddress.push(properties.street);
if ('house_number' in properties) {
streetAddress.push(properties.house_number);
if ('housenumber' in properties) {
streetAddress.push(properties.housenumber);
}
// street address with house number can also be the same as name
if (streetAddress.length > 0) {
Expand All @@ -432,8 +437,8 @@ angular.module('orsApp.utils-service', [])
}
// secondary information
const secondary = [];
if ('postal_code' in properties) {
secondary.push(properties.postal_code);
if ('postalcode' in properties) {
secondary.push(properties.postalcode);
}
if ('neighbourhood' in properties) {
secondary.push(properties.neighbourhood);
Expand All @@ -458,7 +463,7 @@ angular.module('orsApp.utils-service', [])
}
if (secondary.length <= 1 && properties.country !== properties.name) secondary.push(properties.country);
feature.processed.secondary = secondary.join(", ");
feature.processed.place_type = properties.place_type;
feature.processed.place_type = properties.layer;
});
return features;
};
Expand Down
2 changes: 1 addition & 1 deletion app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
'request': function(config) {
const apiKey = orsApikeyFactory.getApiKey() === undefined ? weathercheck : orsApikeyFactory.getApiKey();
let ak = '?api_key=' + apiKey;
if (config.url == ENV.geocoding ||  config.url == ENV.routing || config.url == ENV.analyse || config.url == ENV.pois) {
if (config.url === ENV.geocoding + '/search' || config.url === ENV.geocoding + '/reverse' || config.url === ENV.routing || config.url === ENV.analyse || config.url === ENV.pois) {
config.url = config.url + ak;
}
return config || $q.when(config);
Expand Down

0 comments on commit 234cfb7

Please sign in to comment.