diff --git a/src/GHUtil.js b/src/GHUtil.js index c3bef82..8da73a4 100644 --- a/src/GHUtil.js +++ b/src/GHUtil.js @@ -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) { diff --git a/src/GraphHopperGeocoding.js b/src/GraphHopperGeocoding.js index 605a32c..a3423e7 100644 --- a/src/GraphHopperGeocoding.js +++ b/src/GraphHopperGeocoding.js @@ -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; + } + + } + return qString; }; diff --git a/src/GraphHopperMapMatching.js b/src/GraphHopperMapMatching.js index 76a4b17..221f6c1 100644 --- a/src/GraphHopperMapMatching.js +++ b/src/GraphHopperMapMatching.js @@ -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; diff --git a/src/GraphHopperRouting.js b/src/GraphHopperRouting.js index e95b374..15caa1e 100644 --- a/src/GraphHopperRouting.js +++ b/src/GraphHopperRouting.js @@ -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';