Considering custom Feature Layers by applying restrictions based on dimensions
Blocking a road to vehicles above a certain height
This code sample exposes how to apply penalties blocking road segments depending on dimensions of the vehicles.
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 BlockPoint = { "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 block 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" : "maxHeight", "value" : 320 } ] } ] } ] }, function(result, exception) { createdFeatureLayer = result.binaryFeatureLayer; }); return createdFeatureLayer; }; //----- Route ----- function calculateSpecificRoute(binaryFeatureLayer) { xroute.calculateRoute({ "waypoints": [A, B], "routeOptions": { "binaryFeatureLayer": binaryFeatureLayer }, "requestProfile": { "vehicleProfile": { "dimensions": { "height": "350" }, } }, "resultFields": { "polyline": true }, "geometryOptions": { "responseGeometryTypes": ["GEOJSON"] } }, function(route, exception) { var geoJson = route.polyline.geoJSON; displayGeoJson(geoJson, '#2882C8'); outputString += 'Route = ' + route.distance + ' m in ' + route.travelTime + ' s.'; print(outputString); }); } var segmentIds = getSegmentToBlock(BlockPoint); var newBinaryFeatureLayer = createCustomFeatureLayer(segmentIds); calculateSpecificRoute(newBinaryFeatureLayer);When creating the Feature Layer a maximum height not to be exceeded is filled with the property maxHeight. And during the routing, this maximum height is compared to the height filled in the vehicle profile.
It is also possible to handle other kind of restrictions based on vehicle The term vehicle describes what is being routed or planned for. Vehicles are used in route calculation, distance matrix calculation and effectively also in tour planning. In route calculation, vehicle properties like overall size, weight and speed are in focus. In tour planning, it is vehicle properties like capacity and availability. Commonly a vehicle is motorized, like a truck - including its trailer or a car. However also a bike or even a pedestrian are included in this definition. dimensions such as width and length or restrictions based on the vehicle weight. All dimension restrictions are documented in the PTV_RoadAttributestheme documentation.