Considering custom Feature Layers by applying absolute speed
The custom Feature Layers can be used to set the absolute speed for a segment.
The following code sample exposes how to apply absolute speed 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 getSegmentToEdit(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(segmentIdToEdit) { var createdFeatureLayer; xdata.createFeatureLayer({ "themeId" : "PTV_RoadAttributes", "features" : [ { "segmentIds" : [ segmentIdToEdit ], "descriptions" : [ { "attributes" : [ { "key" : "absoluteSpeed", "value" : 5 } ] } ] } ] }, 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 = getSegmentToEdit(nearPoint); var newBinaryFeatureLayer = createCustomFeatureLayer(segmentIds); calculateSpecificRoute(newBinaryFeatureLayer);When creating the Feature Layer the absolute speed of the segment is set. This absolute speed is then considered during the routing.
The applied absolute speed overwrites all other speeds ; i.e. PTV_SpeedPatterns, PTV_TraficIncidents, or any other FeatureLayers.