Considering custom Feature Layers in content snapshots
The example below shows the creation of a custom Feature Layer, as persistent file, containing a blocking segment. Afterwards, a content snapshot is created, including this blocking layer. And finally a route is calculated which takes the newly content snapshot into account. Therefore, the JavaScript bindings to the xRoute and xData service APIs are used:
Note that, the Feature Layer must be a persistent file. Content snapshots do not work with binary Feature Layer.
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 blockedSegment = JSON.stringify({ "type": "LineString", "coordinates": [ [6.1259964212, 49.589456027], [6.1274237788, 49.590072889] ] }); var outputString = ""; var contentSnapshotId = ""; var map = new L.Map('map', { center: [49.587, 6.220], zoom: 13 }); // Add tile layer to map new L.tileLayer.xserver(xServerUrl + '/services/rest/XMap/experimental/tile/{z}/{x}/{y}' + '?layers=background,transport,labels&contentType=JSON', { pane: "overlayPane", maxZoom: 20, }).addTo(map); //----- Create Feature Layer ----- async function createFeatureLayer() { let promise = new Promise((resolve, reject) => { xdata.createFeatureLayer({ "scope": "blockingusecase", "themeId": "PTV_RoadAttributes", "featureScenario": "UseCaseBlocking", "features": [{ "segmentIds": ["SEGM00027f681fa7v6PFAetxOtsA+2Q8yxX7azPNAuxrBck="], "descriptions": [{ "attributes": [{ "key": "opening", "value": 0 }] }] }], "resultFields": { "binaryFeatureLayer": false } }, function(result, exception) { if (result) { resolve(); } else { reject(null); } }); }); await promise; } //----- Create content snapshot ----- async function createContentSnapshot() { let promise = new Promise((resolve, reject) => { xdata.createContentSnapshot({ "scope": "blockingusecase", "label": "SnapshotUseCaseBlocking" }, function(result, exception) { if (result) { contentSnapshotId = result.contentSnapshotDescription.id; resolve(result.contentSnapshotDescription.id); } else { reject(null); } }); }); await promise; } //----- Calculate the route using the generated content snapshot ----- async function calculateSpecificRoute() { var options = { "contentSnapshotId": contentSnapshotId }; let promise = new Promise((resolve, reject) => { xroute.calculateRoute({ "scope": "blockingusecase", "waypoints": [A, B], "resultFields": { "polyline": true }, "geometryOptions": { "responseGeometryTypes": ["GEOJSON"] }, "resultFields": { "polyline":true }, "routeOptions": options, "requestProfile": { "featureLayerProfile": { "themes": [{ "id": "PTV_RoadAttributes", "enabled": "true", "featureScenarios": ["UseCaseBlocking"] }] } } }, function(route, exception) { if (route) { var geoJson = route.polyline.geoJSON; displayGeoJson(geoJson, '#2882C8'); outputString += 'route= ' + route.distance + ' m in ' + route.travelTime + ' s'; print(outputString); resolve(route); } else { reject(null); } }); }); await promise; } //----- Delete the generated data ----- function deleteContentSnapshot() { xdata.deleteContentSnapshot({ "scope": "blockingusecase", "id": contentSnapshotId }); } function deleteFeatureLayer() { xdata.deleteFeatureLayer({ "scope": "blockingusecase", "themeId": "PTV_RoadAttributes", "featureScenario": "UseCaseBlocking" }); } function displayGeoJson(geoJson, color) { var jsonObject = JSON.parse(geoJson); var geoJsonLayer = new L.GeoJSON(jsonObject, { style: { color: color, weight: 8 } }).addTo(map); map.fitBounds(geoJsonLayer.getBounds()); }; // Process to use a custom Feature Layer with a content snapshot and use it in a route calculation. // At the end, data are deleted. createFeatureLayer() .then(createContentSnapshot) .then(deleteFeatureLayer) .then(calculateSpecificRoute) .then(deleteContentSnapshot); // Display the blocking segment displayGeoJson(blockedSegment, '#481111');Afterwards, content snapshots with custom blocking can be used to create a distance matrix as follow or a high performance performance routing network.