Skip to content

geocode - allow osm_tag entries in tags #61

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion src/GHUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ GHUtil.prototype.extractError = function (res, url) {
msg = res;
}

return new Error(msg + " - for url " + url);
const error = new Error(msg);

if(res && res.body && res.body.hints) {
error.hints = res?.body?.hints;
}

return error;
};

GHUtil.prototype.isArray = function (value) {
Expand Down
14 changes: 14 additions & 0 deletions src/GraphHopperGeocoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ GraphHopperGeocoding.prototype.getParametersAsQueryString = function (args) {
if (args.limit)
qString += "&limit=" + args.limit;

if (args.osm_tag) {

if(args.osm_tag.length) {

for(var j=0; j < args.osm_tag.length;++j) {
qString += "&osm_tag=" + args.osm_tag[j];
}

} else {
qString += "&osm_tag=" + args.osm_tag;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In both cases encodeURIComponent would be important.

}

}

return qString;
};

Expand Down
27 changes: 27 additions & 0 deletions src/GraphHopperMapMatching.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,37 @@ GraphHopperMapMatching.prototype.getParametersAsQueryString = function (args) {

if (args.vehicle)
qString += "&vehicle=" + args.vehicle;

if (args.details)
qString += this.flatParameter('details', args.details);

return qString;
};

GraphHopperMapMatching.prototype.flatParameter = function (key, val) {
var url = "";
var arr;
var keyIndex;

if (ghUtil.isObject(val)) {
arr = Object.keys(val);
for (keyIndex in arr) {
var objKey = arr[keyIndex];
url += this.flatParameter(key + "." + objKey, val[objKey]);
}
return url;

} else if (ghUtil.isArray(val)) {
arr = val;
for (keyIndex in arr) {
url += this.flatParameter(key, arr[keyIndex]);
}
return url;
}

return "&" + encodeURIComponent(key) + "=" + encodeURIComponent(val);
};

GraphHopperMapMatching.prototype.doRequest = function (content, reqArgs) {
var that = this;

Expand Down
4 changes: 3 additions & 1 deletion src/GraphHopperRouting.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ var ghUtil = new GHUtil();
GraphHopperRouting = function (args) {
this.points = [];
this.host = "https://graphhopper.com/api/1";
this.vehicle = "car";
if(args.profile === undefined) {
this.vehicle = "car";
}
this.debug = false;
this.data_type = 'application/json';
this.locale = 'en';
Expand Down