-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27885f6
commit 9b6d01b
Showing
9 changed files
with
337 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const rs = ((_) => { | ||
let request = function (from, to, apikey, profile, callback) { | ||
let xhr = new XMLHttpRequest({ | ||
mozSystem: true, | ||
"Content-Type": "application/json", | ||
}); | ||
xhr.open( | ||
"GET", | ||
"https://api.openrouteservice.org/v2/directions/" + | ||
profile + | ||
"?api_key=" + | ||
apikey + | ||
"&" + | ||
"start=" + | ||
from + | ||
"&" + | ||
"end=" + | ||
to | ||
); | ||
|
||
xhr.timeout = 4000; | ||
|
||
xhr.ontimeout = function (e) {}; | ||
|
||
xhr.onload = function () { | ||
if (xhr.status == 200) { | ||
callback(JSON.parse(xhr.responseText)); | ||
} | ||
if (xhr.status == 403) { | ||
console.log("access forbidden"); | ||
} | ||
// analyze HTTP status of the response | ||
if (xhr.status != 200) { | ||
console.log(xhr.status); | ||
helper.side_toaster("the route could not be loaded.", 2000); | ||
} | ||
}; | ||
|
||
xhr.onerror = function (err) { | ||
console.log(err); | ||
}; | ||
xhr.send(null); | ||
}; | ||
|
||
let addPoint = function (type, action, latlng) { | ||
if (action == "add") { | ||
if (type == "start") { | ||
routing.start = latlng.lng + "," + latlng.lat; | ||
} | ||
|
||
if (type == "end") { | ||
routing.end = latlng.lng + "," + latlng.lat; | ||
} | ||
} | ||
}; | ||
|
||
return { | ||
request, | ||
addPoint, | ||
}; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.