1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Test Géoservices Route API Rest</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<h2>Requete API route (GET/POST)</h2>
<button onclick="route('GET')">Méthode Get</button>
<button onclick="route('POST')">Méthode Post</button>
<br>
<pre id="result"></pre>
<script type="text/javascript">
function route(method) {
$("#result").empty();
var data = {
"resource": "bdtopo-osrm",
"optimization": "fastest",
"geometryFormat": "polyline",
"steps": true,
"bbox": true,
"start": "2.337306,48.849319",
"end": "2.367776,48.852891",
"profile": "car"
};
console.log("data json", data);
var headers = null;
if (method == "GET") {
data = $.param(data);
} else {
data = JSON.stringify(data);
headers = { "accept": "application/json", "Content-Type": "application/json" };
}
var settings = {
"url": "https://wxs.ign.fr/calcul/geoportail/itineraire/rest/1.0.0/route",
"method": method,
"headers": headers,
//"dataType": 'json',
//"dataType": 'jsonp',
//"crossDomain": true,
"timeout": 0,
"data": data,
};
console.log("settings ajax", settings);
$.ajax(settings)
.done(function (response) {
console.log("response ajax done", response);
$("#result").text(JSON.stringify(response, undefined, 2));
})
.fail(function(jqXHR, textStatus, errorThrown) {
console.log("response ajax fail", textStatus, errorThrown);
$("#result").text(textStatus);
});
}
</script>
</body>
</html> |
Partager