Calculating Leg Details
We start by calculating the leg details . This initial step ensures accurate and comprehensive information for each segment of the journey.
- NodeJS
const fetch = require("node-fetch")
fetch("https://backend.impargo.eu/", {
method: "POST",
headers: {
"authorization": token,
"content-type": "application/json",
},
body: JSON.stringify({
"operationName": "CalculateLeg",
"variables": {
"legInput": {
"start": {
"lat": 51.48924,
"lon": 5.56553
},
"destination": {
"lat": 52.46397,
"lon": 13.40313
},
"viapoints": [],
"routingOptions": {
"mapEngine": "HERE_MAP",
"settings": {
"axis": 5,
"weight": 40,
"time": "day",
"euronorm": "6",
"co2EmissionClass": "1"
},
"costsPerDistance": 0.6306965476190476,
"costsPerTime": 30.63235416666667,
"shippedHazardousGoods": [],
"maxAxle": 8,
"maxHeight": 4,
"routingMode": "fastest",
"considerTraffic": false
}
}
},
"query": `query CalculateLeg($legInput: LegInput!) {
calculateLeg(legInput: $legInput) {
...LegData
__typename
}
}
fragment Warning on Warning {
hasFerry
hasVehicleMismatch
hasRoutingOptionViolation
noAlternativeRouteFound
__typename
}
fragment CalculatedRouteData on LegRoute {
distance
time
infoIcons {
code
maneuver {
position {
lat
lon
__typename
}
__typename
}
__typename
}
segments {
name
type
distance
time
encodedCoordinates
__typename
}
__typename
}
fragment LegData on Leg {
_id
createdAt
warnings {
...Warning
__typename
}
calculatedRoute {
...CalculatedRouteData
__typename
}
__typename
}
`
})
})
.then(response => response.json())
.then(data => {
console.log("Output:", data);
})
.catch(error => {
console.error("Error:", error);
});
- Response
{
"data": {
"calculateLeg": {
"_id": "65c7e4cdc3c846c3e2922465",
"createdAt": "2024-02-10T21:04:13.758Z",
"warnings": {
"hasFerry": false,
"hasVehicleMismatch": false,
"hasRoutingOptionViolation": false,
"noAlternativeRouteFound": null,
"__typename": "Warning"
},
"calculatedRoute": {
"distance": 723375,
"time": 32716,
"infoIcons": [
{
"code": "accident",
"maneuver": {
"position": {
"lat": 48.712459999999886,
"lon": 2.2836999999999956,
"__typename": "Coordinates"
},
"__typename": "ManeuverType"
},
"__typename": "InfoIcon"
},
{
"code": "roadworks",
"maneuver": {
"position": {
"lat": 48.802989999999895,
"lon": 2.342019999999991,
"__typename": "Coordinates"
},
"__typename": "ManeuverType"
},
"__typename": "InfoIcon"
},
{
"code": "tollBooth",
"maneuver": {
"position": {
"lat": 43.54621,
"lon": 1.50041,
"__typename": "Coordinates"
},
"__typename": "ManeuverType"
},
"__typename": "InfoIcon"
}
],
"segments": [
{
"name": "Lieu-dit Berline",
"type": "NOT_SPECIAL",
"distance": 62,
"time": 7,
"encodedCoordinates": "BF-4yoI0usLRrCDZ",
"__typename": "Segment"
},
{
"name": "A20",
"type": "NOT_SPECIAL",
"distance": 1336,
"time": 110,
"encodedCoordinates": "",
"__typename": "Segment"
},
{
"name": "L'Occitane",
"type": "NOT_SPECIAL",
"distance": 116970,
"time": 4871,
"encodedCoordinates": "",
"__typename": "Segment"
},
{
"name": "Boulevard du Palais",
"type": "NOT_SPECIAL",
"distance": 235,
"time": 61,
"encodedCoordinates": "BF47lqJ4_pOoGoGeYqCuB",
"__typename": "Segment"
},
{
"name": "Quai de l'Horloge",
"type": "NOT_SPECIAL",
"distance": 393,
"time": 109,
"encodedCoordinates": "BFonmqJwpqOgBhDevCQ9BCFMtBUjDUnDCtDoB5IElBGnCEV",
"__typename": "Segment"
}
],
"__typename": "LegRoute"
},
"__typename": "Leg"
}
}
}
Route Details: Time, Cost, Tolls and Distance
Once the leg details are calculated, we can retrieve the specific details of the route, including the time, cost, tolls and distance. This comprehensive breakdown allows for precise planning and optimization of your logistics operations.
- NodeJS
const fetch = require("node-fetch")
fetch("https://backend.impargo.eu/", {
method: 'POST',
headers: {
'authorization': token,
'content-type': 'application/json',
},
body: JSON.stringify([
{
operationName: 'CalculateRouteDetails',
variables: { legs: [leg_id] },
query: `query CalculateRouteDetails($legs: [ObjectId!]!) {
calculateRouteDetails(legs: $legs) {
...RouteDetailsData
__typename
}
}
fragment TollSummary on TollSummary {
amount
distanceCharged
distanceFree
__typename
}
fragment TollDetailsData on TollDetails {
amount
speculativeOrHistoricalAmounts {
specifier
amount
__typename
}
distanceCharged
distanceFree
country
type
__typename
}
fragment TollSystem on TollSystem {
name
country
amount
type
__typename
}
fragment TollData on Toll {
summary {
...TollSummary
__typename
}
details {
...TollDetailsData
__typename
}
byCountryAndTollSystem {
...TollSystem
__typename
}
__typename
}
fragment RouteDetailsData on RouteDetails {
_id
legs {
_id
calculatedRoute {
distance
time
__typename
}
tolls {
...TollData
__typename
}
__typename
}
tolls {
...TollData
__typename
}
__typename
}
`,
},
]),
})
.then(response => response.json())
.then(data => {
const graphqlData = data[0]?.data.calculateRouteDetails;
console.log("GraphQL Response:", graphqlData);
})
.catch(error => {
console.error('Error fetching GraphQL data:', error);
});
- Response
[
{
"data": {
"calculateRouteDetails": {
"_id": "66013f0657e53559d687639f",
"legs": [
{
"_id": "66013f05c571e0a24a5e7553",
"calculatedRoute": {
"distance": 1383083,
"time": 70368,
"__typename": "LegRoute"
},
"tolls": {
"summary": {
"amount": 271.74,
"distanceCharged": 873.1239999999999,
"distanceFree": 509.95899999999995,
"__typename": "TollSummary"
},
"details": [
{
"amount": 204,
"speculativeOrHistoricalAmounts": [
{
"specifier": "DE_DEC_2023_CO2-1",
"amount": 204,
"__typename": "TollSpeculation"
},
{
"specifier": "DE_DEC_2023_CO2-2",
"amount": 199.1907,
"__typename": "TollSpeculation"
},
{
"specifier": "DE_DEC_2023_CO2-3",
"amount": 194.50385999999997,
"__typename": "TollSpeculation"
},
{
"specifier": "DE_DEC_2023_CO2-4",
"amount": 157.59499499999998,
"__typename": "TollSpeculation"
},
{
"specifier": "DE_DEC_2023_CO2-5",
"amount": 0,
"__typename": "TollSpeculation"
},
{
"specifier": "DE_JUL_2024",
"amount": 204,
"__typename": "TollSpeculation"
},
{
"specifier": "DE_2023",
"amount": 111.31244999999998,
"__typename": "TollSpeculation"
}
],
"distanceCharged": 585.8549999999999,
"distanceFree": 1.206,
"country": "DE",
"type": "DISTANCE_CHARGE",
"__typename": "TollDetails"
},
{
"amount": 0,
"speculativeOrHistoricalAmounts": [],
"distanceCharged": 0,
"distanceFree": 61.717999999999996,
"country": "FR",
"type": "DISTANCE_CHARGE",
"__typename": "TollDetails"
},
{
"amount": 17.4,
"speculativeOrHistoricalAmounts": [],
"distanceCharged": 2.0300000000000002,
"distanceFree": 447.03499999999997,
"country": "GB",
"type": "MIXED",
"__typename": "TollDetails"
},
{
"amount": 12,
"speculativeOrHistoricalAmounts": [],
"distanceCharged": 74.609,
"distanceFree": 0,
"country": "NL",
"type": "DAILY_VIGNETTE",
"__typename": "TollDetails"
},
{
"amount": 38.34,
"speculativeOrHistoricalAmounts": [],
"distanceCharged": 210.63000000000002,
"distanceFree": 0,
"country": "BE",
"type": "DISTANCE_CHARGE",
"__typename": "TollDetails"
}
],
"byCountryAndTollSystem": [
{
"name": "TOLL COLLECT GMBH",
"country": "DE",
"amount": 204,
"type": "DISTANCE_CHARGE",
"__typename": "TollSystem"
},
{
"name": "EUROVIGNETTE NETHERLANDS",
"country": "NL",
"amount": 12,
"type": "DAILY_VIGNETTE",
"__typename": "TollSystem"
},
{
"name": "VIAPASS FLANDERS",
"country": "BE",
"amount": 38.34,
"type": "DISTANCE_CHARGE",
"__typename": "TollSystem"
},
{
"name": "UK HGV LEVY ENGLAND",
"country": "GB",
"amount": 10.44,
"type": "DAILY_VIGNETTE",
"__typename": "TollSystem"
},
{
"name": "CONNECT PLUS (M25) LIMITED",
"country": "GB",
"amount": 6.96,
"type": "DISTANCE_CHARGE",
"__typename": "TollSystem"
}
],
"__typename": "Toll"
},
"__typename": "Leg"
}
],
"tolls": {
"summary": {
"amount": 271.74,
"distanceCharged": 873.1239999999999,
"distanceFree": 509.95899999999995,
"__typename": "TollSummary"
},
"details": [
{
"amount": 204,
"speculativeOrHistoricalAmounts": [
{
"specifier": "DE_DEC_2023_CO2-1",
"amount": 204,
"__typename": "TollSpeculation"
},
{
"specifier": "DE_DEC_2023_CO2-2",
"amount": 199.1907,
"__typename": "TollSpeculation"
},
{
"specifier": "DE_DEC_2023_CO2-3",
"amount": 194.50385999999997,
"__typename": "TollSpeculation"
},
{
"specifier": "DE_DEC_2023_CO2-4",
"amount": 157.59499499999998,
"__typename": "TollSpeculation"
},
{
"specifier": "DE_DEC_2023_CO2-5",
"amount": 0,
"__typename": "TollSpeculation"
},
{
"specifier": "DE_JUL_2024",
"amount": 204,
"__typename": "TollSpeculation"
},
{
"specifier": "DE_2023",
"amount": 111.31244999999998,
"__typename": "TollSpeculation"
}
],
"distanceCharged": 585.8549999999999,
"distanceFree": 1.206,
"country": "DE",
"type": "DISTANCE_CHARGE",
"__typename": "TollDetails"
},
{
"amount": 0,
"speculativeOrHistoricalAmounts": [],
"distanceCharged": 0,
"distanceFree": 61.717999999999996,
"country": "FR",
"type": "DISTANCE_CHARGE",
"__typename": "TollDetails"
},
{
"amount": 17.4,
"speculativeOrHistoricalAmounts": [],
"distanceCharged": 2.0300000000000002,
"distanceFree": 447.03499999999997,
"country": "GB",
"type": "MIXED",
"__typename": "TollDetails"
},
{
"amount": 12,
"speculativeOrHistoricalAmounts": [],
"distanceCharged": 74.609,
"distanceFree": 0,
"country": "NL",
"type": "DAILY_VIGNETTE",
"__typename": "TollDetails"
},
{
"amount": 38.34,
"speculativeOrHistoricalAmounts": [],
"distanceCharged": 210.63000000000002,
"distanceFree": 0,
"country": "BE",
"type": "DISTANCE_CHARGE",
"__typename": "TollDetails"
}
],
"byCountryAndTollSystem": [
{
"name": "TOLL COLLECT GMBH",
"country": "DE",
"amount": 204,
"type": "DISTANCE_CHARGE",
"__typename": "TollSystem"
},
{
"name": "EUROVIGNETTE NETHERLANDS",
"country": "NL",
"amount": 12,
"type": "DAILY_VIGNETTE",
"__typename": "TollSystem"
},
{
"name": "VIAPASS FLANDERS",
"country": "BE",
"amount": 38.34,
"type": "DISTANCE_CHARGE",
"__typename": "TollSystem"
},
{
"name": "UK HGV LEVY ENGLAND",
"country": "GB",
"amount": 10.44,
"type": "DAILY_VIGNETTE",
"__typename": "TollSystem"
},
{
"name": "CONNECT PLUS (M25) LIMITED",
"country": "GB",
"amount": 6.96,
"type": "DISTANCE_CHARGE",
"__typename": "TollSystem"
}
],
"__typename": "Toll"
},
"__typename": "RouteDetails"
}
}
}
]