Custom blocking with xRoute and xDima
Feature Layer can also be used with xDima to create a distance matrix. The example below shows the creation of a distance matrix and compare results with xRoute. Therefore, the JavaScript bindings to the xRoute, xData and xDima service APIs are used:
var A = { "$type": "OffRoadWaypoint", "location": { "offRoadCoordinate": { "x": 6.124995946884156, "y": 49.589077328363246 } } }; var B = { "$type": "OffRoadWaypoint", "location": { "offRoadCoordinate": { "x": 6.128221, "y": 49.589744 } } }; var startLocation = { "$type": "OffRoadRouteLocation", "offRoadCoordinate": { "x": 6.124995946884156, "y": 49.589077328363246 } }; var destinationLocation = { "$type": "OffRoadRouteLocation", "offRoadCoordinate": { "x": 6.128221, "y": 49.589744 } }; //----- Create Feature Layer ----- var binaryFeatureLayer = ""; async function createFeatureLayerWithBlockedSegment() { let promise = new Promise((resolve, reject) => { xdata.createFeatureLayer({ "themeId": "PTV_RoadAttributes", "features": [{ "segmentIds": ["SEGM00027f681fa7v6PFAetxOtsA+2Q8yxX7azPNAuxrBck="], "descriptions": [{ "attributes": [{ "key": "opening", "value": 0 }] }] }], "resultFields": { "binaryFeatureLayer": true } }, function(result, exception) { if (result) { binaryFeatureLayer = result.binaryFeatureLayer; resolve(result); } else { reject(null); } }); }); await promise; } //----- Create distance matrix ----- var dimaDistance = 0; var dimaTravelTime = 0; async function createAndGetDistanceMatrix() { let promise = new Promise((resolve, reject) => { xdima.createDistanceMatrix({ "$type": "CreateAndGetDistanceMatrixRequest", "startLocations": [startLocation], "destinationLocations": [destinationLocation], "resultFields": { "distances": true, "travelTimes": true }, "distanceMatrixOptions": { "binaryFeatureLayer": binaryFeatureLayer } }, function(result, exception) { if (result) { dimaDistance = result.contents.distances[0]; dimaTravelTime = result.contents.travelTimes[0]; resolve(result); } else { reject(null); } }); }); await promise; } //----- Compare results between xRoute and xDima ----- async function compareResults() { // Using xRoute var routeResult; let xRoutePromise = new Promise((resolve, reject) => { xroute.calculateRoute({ "waypoints": [A, B], "routeOptions": { "binaryFeatureLayer": binaryFeatureLayer } }, function(route, exception) { if (route) { routeResult = route; resolve(route); } else { reject(null); } }); }); await xRoutePromise; // Display result var haveTheSameResults = routeResult.distance === dimaDistance && routeResult.travelTime === dimaTravelTime; if (haveTheSameResults) { print("xDima and xRoute have the same results."); } else { print("An error occurred."); } } // Process to use a custom Feature Layer as binary object with a distance matrix and then compare results between xdima and xroute. createFeatureLayerWithBlockedSegment() .then(createAndGetDistanceMatrix) .then(compareResults);