Skip to content

Commit

Permalink
feat: add html example for snap
Browse files Browse the repository at this point in the history
Co-authored-by: rizwan <[email protected]>
  • Loading branch information
TheGreatRefrigerator and rizwan committed Jul 5, 2024
1 parent 1f630c4 commit 634eab6
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions examples/snap.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>ORS-js lib examples</title>
<script type="module" src="../dist/ors-js-client.js"></script>
</head>
<body>
<div>
<h1>ORS-js lib examples</h1>
<section>
<h2>Driving car snapping</h2>
<div id="driving-car-snap">
<script type='module'>
import apiKey from './apiKey.js'
window.onload = function() {
const node = document.getElementById("driving-car-snap")

const Snap = new Openrouteservice.Snap({
api_key: apiKey
})

Snap.calculate({
locations: [[8.690958, 49.404662], [8.687868, 49.390139]],
radius: 300,
profile: "driving-car",
format: "json",
api_version: 'v2',
})
.then(function(json) {
// Add your own result handling here
let response = JSON.stringify(json, null, "\t")
console.log(response);
response = response.replace(/(\n)/g, '<br>');
response = response.replace(/(\t)/g, '&nbsp;&nbsp;');
node.innerHTML = "<h3>Response</h3><p>" + response + "</p>";
})
.catch(function(err) {
let response = JSON.stringify(err, null, "\t")
console.error(response);
response = response.replace(/(\n)/g, '<br>');
response = response.replace(/(\t)/g, '&nbsp;&nbsp;');
node.innerHTML = "<h3>Error</h3><p>" + response + "</p>";
})
}
</script>
</div>

</section>
</div>
</body>
</html>

0 comments on commit 634eab6

Please sign in to comment.