Considering custom Feature Layers by applying extra driving time
The custom Feature Layers can be used to add extra driving time on a segment.
The following code sample exposes how to apply such an extra driving time to a segment.
var A = { "$type": "OffRoadWaypoint", "location": { "offRoadCoordinate": { "x": 6.111967, "y": 49.614536 } } }; var B = { "$type": "OffRoadWaypoint", "location": { "offRoadCoordinate": { "x": 6.106796, "y": 49.615252 } } }; var nearPoint = { "x": 6.109486, "y": 49.614904 }; var outputString = ""; var map = new L.Map('map', { center: [49.615525, 6.109560], zoom: 16 }); // Add tile layer to map new L.tileLayer.xserver(xServerUrl + '/services/rest/XMap/experimental/tile/{z}/{x}/{y}' + '?layers=background,transport,labels,PTV_TruckAttributes' + '&contentType=JSON', { pane: "overlayPane", maxZoom: 20, }).addTo(map); // Display the point L.circle([49.615525, 6.109560], {radius: 3}).addTo(map); //----- Find segment near coordinate ----- function getSegmentToBlock(searchCoord) { var foundSegmentId; xdata.getSegments({ "$type": "SegmentsByCoordinateRequest", "resultFields": { "polyline": true, "descriptors": true }, "coordinate": searchCoord, "geometryOptions": { "responseGeometryTypes": ["GEOJSON"] } }, function(result, exception) { var geoJson = result.segments[0].polyline.geoJSON; displayGeoJson(geoJson, '#481111'); foundSegmentId = result.segments[0].id; }); return foundSegmentId; } 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()); }; //----- Create FeatureLayer ----- function createCustomFeatureLayer(segmentIdToBlock) { var createdFeatureLayer; xdata.createFeatureLayer({ "themeId" : "PTV_RoadAttributes", "features" : [ { "segmentIds" : [ segmentIdToBlock ], "descriptions" : [ { "attributes" : [ { "key" : "extraDrivingTime", "value" : 5000 } ] } ] } ] }, function(result, exception) { createdFeatureLayer = result.binaryFeatureLayer; }); return createdFeatureLayer; }; //----- Route ----- function calculateStandardRoute() { xroute.calculateRoute({ "waypoints": [A, B], "resultFields": { "polyline": true }, "geometryOptions": { "responseGeometryTypes": ["GEOJSON"] } }, function(route, exception) { var geoJson = route.polyline.geoJSON; displayGeoJson(geoJson, '#2882C8'); outputString += 'travel time (normal) = ' + route.travelTime + ' s '; print(outputString); }); } function calculateSpecificRoute(binaryFeatureLayer) { xroute.calculateRoute({ "waypoints": [A, B], "routeOptions": { "binaryFeatureLayer": binaryFeatureLayer }, "resultFields": { "polyline": true }, "geometryOptions": { "responseGeometryTypes": ["GEOJSON"] } }, function(route, exception) { var geoJson = route.polyline.geoJSON; displayGeoJson(geoJson, '#2882C8'); outputString += 'travel time (using custom feature layer) = ' + route.travelTime + ' s '; print(outputString); }); } calculateStandardRoute(); var segmentIds = getSegmentToBlock(nearPoint); var newBinaryFeatureLayer = createCustomFeatureLayer(segmentIds); calculateSpecificRoute(newBinaryFeatureLayer);When creating the Feature Layer an extra driving time of 5 seconds is set to the segment. During the routing, this extra driving time is added to the current driving time of the segment.
It is also added whatever the way the driving time is calculated ; i.e. using PTV_SpeedPatterns, PTV_TraficIncidents, or any other FeatureLayers.