Creating and considering custom Feature Layers blocking or opening roads

Blocking the closest road to a location

The first example is the most basic example. It shows how to create a custom Feature Layer in binary mode that blocks a road segment by finding a segment via a given coordinate. Then, a route is calculated which takes the newly created Feature Layer into account. Therefore, the JavaScript bindings to the xRoute and xData service APIs are used.

The function getSegmentToBlock() returns the SegmentId of the road segment to be blocked. The function createFeatureLayer() uses the SegmentId to create the custom Feature Layer in binary mode. At the creation of the custom Feature Layer, the KeyValuePair is filled with "opening = 0" which has the effect of closing the road. The function calculateSpecificRoute() uses the binary custom Feature Layer to calculate the route.

Of course, the requests can be improved to consider other parameters.

Blocking a road in a given direction with a time-dependent restriction

Please pay attention to the digitization direction of the segments, when blocking a road. By default, custom Feature Layers apply the restrictions in both directions. The example below shows how to block a segment in a single direction (here in POLYLINE_DIRECTION). To visualize the digitization direction of the segment, the first point of its polyline is represented by a green circle, and the last point by an orange circle. Moreover, in createFeatureLayer(), a GDF time-domain is applied to block the road between 8.00 am and 6.00 pm only, every day of the week.

Opening a one-way street in the reverse direction

Sometimes it is necessary to open a blocked road, e.g. a pedestrian area or even a one-way street in reverse direction. This can be useful for emergency or intervention vehicles (police, firefighter, ambulances). Or this can be useful in case of temporary openings due to roadworks, or when a recent change of driving direction is not yet included in the map. For that, the KeyValuePair "opening = 1" can be used. The same mechanism can be used to open in both direction (or in a single direction). But note that in the case of one-way the polyline geometry describing one segment follows by default the driving direction.

In this example a vehicle can take a roundabout in the opposite direction.

Be careful when opening one-way roads. Violations will not be reported if a route takes a segment which has been open by a custom Feature Layer. In addition, opening a route resets all its penalties, except those set by a custom Feature Layer.