Select to view content in your preferred language

How to Avoid U-Turns in Routing Directions

707
2
Jump to solution
06-02-2024 08:11 PM
LeoDeng
Frequent Contributor

Hi All,

Here is one question about U-Turns.

After set the restrictUTurns as "esriNFSBNoBacktrack" (means U-Turn is not allowed), there still could be "Make a U-Turn" in driving directions. How to avoid it ?

LeoDeng_0-1717384439171.pngLeoDeng_1-1717384482576.png

LeoDeng_2-1717384530095.png

Besides, in the example code, there is a "Make a U-turn" from stop 1 to stop 2.

LeoDeng_0-1717552646639.png

However, there is "Turn left ... " and "Turn left ... " from stop 3 to stop 4. 

LeoDeng_1-1717552660992.png

How to distinguish these two difference scenarios?

 

 

You can reproduce this issue by the following code.

 

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="https://js.arcgis.com/4.29/esri/themes/light/main.css">
    <script src="https://js.arcgis.com/4.29/"></script>
    <title>U-Turn Directions</title>
    <style>
        html, body, #viewDiv {
            padding: 0;
            margin: 0;
            height: 100%;
            width: 100%;
        }
    </style>
    <script>
        require(["esri/Map",
            "esri/views/MapView",
            "esri/layers/RouteLayer",
            "esri/rest/support/Stop",
            "esri/widgets/Directions"],
        function (Map, MapView, RouteLayer, Stop, Directions) {

            (async () =>
            {
                const apiKey = <YOUR_API_KEY>;  // Replace with your api key.

                const center = [-73.9056, 42.8041];

                const stops = [
                    new Stop({ geometry: { x: -73.905003, y: 42.803639 }, name: "Stop 1", locationType: "stop", sequence: 1, curbApproach: "right-side-of-vehicle" }),
                    new Stop({ geometry: { x: -73.905278, y: 42.803887 }, name: "Stop 2", locationType: "stop", sequence: 2, curbApproach: "right-side-of-vehicle" }),
                    new Stop({ geometry: { x: -73.906477, y: 42.804605 }, name: "Stop 3", locationType: "stop", sequence: 3, curbApproach: "right-side-of-vehicle" }),
                    new Stop({ geometry: { x: -73.906614, y: 42.804673 }, name: "Stop 4", locationType: "stop", sequence: 4, curbApproach: "right-side-of-vehicle" })
                ];

                const routeLayer = new RouteLayer({ stops });

                const map = new Map({
                    basemap: "streets-vector",
                    layers: [routeLayer]
                });
                const view = new MapView({
                    map: map,
                    container: "viewDiv",
                    zoom: 16,
                    center: center
                });
                const directionsWidget = new Directions({
                    apiKey: apiKey,
                    view: view,
                    layer: routeLayer
                });

                view.ui.add(directionsWidget, {
                    position: "top-right"
                });

                await Promise.all([view.when(), routeLayer.load(), directionsWidget.when()]);

                const restrictUTurns = "no-backtrack";  // U-Turn is not allowed
                const routeParameters = { apiKey, restrictUTurns }
                const results = await routeLayer.solve(routeParameters);

                routeLayer.update(results);

                await view.goTo(routeLayer.routeInfo.geometry);

            })();
        });
    </script>
</head>
<body>
    <div id="viewDiv"></div>
</body>
</html>

 


The driving directions given by ArcGIS Pro (3.2.1) is different to the ArcGIS Online.

LeoDeng_2-1717552852103.png

Is there anything I missed for the U-Turns?

Environment

ArcGIS Online
JavaScript API 4.29 (latest)
ArcGIS Pro (3.2.1)

 

Thanks,
Leo

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RodneyConger
Esri Contributor

There is currently no way to affect this behavior with routes solved through ArcGIS Online

View solution in original post

2 Replies
RodneyConger
Esri Contributor

There is currently no way to affect this behavior with routes solved through ArcGIS Online

John_Guilfoyle
Emerging Contributor

 

The question lacks context.  Are you delivering a small parcel or filling a Natural Gas tank?

If you Can, change the associated Network Position (Source OID and PosAlong) of the first and last stops (in this example). 
You will lose four Left Turns (two U-Turns) and be left with a single Right Turn.
If you start the route by heading West on Eastern Parkway, Park the vehicle, and walk across the grass center median, you can visit both stops on that block, continue West, and then take a Right turn on Lakewood Avenue heading North. You could again walk across the grass center median to visit both stops without having any Left Turns across Traffic or U-Turns.
After departure, you could stop by Rosario's Trattoria for a Lasagna or a Pizza.
Schenectady.jpg



0 Kudos