1

I am using the ArcGIS Javascript3.22 API routeTask to determine the route around polygon barriers.

How do I properly define the polygon barriers?

What I have tried is:

  routeTask = new RouteTask("https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World");
  routeParams = new RouteParameters();
  routeParams.polygonBarriers =  new FeatureSet("http://arcgis-geog865-942335747.us-east-1.elb.amazonaws.com/arcgis/rest/services/RoadLimit_feature_server/FeatureServer/0");

But, when I include the last line above (routeParams.polygonBarriers...) in my code the page stop's working.

1 Answer 1

1

You can only create a FeatureSet pasing a JSON as a parameter, not a URL. That's the reason your code fails. You can see it in the FeatureSet-Documentation

So you have to query the FeatureService, get back the results as JSON, and then you can pass it to the RouteParameters. Something like this (NOT TESTED)

routeTask = new RouteTask("https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World");
routeParams = new RouteParameters();
routeParams.polygonBarriers =  new FeatureSet("http://arcgis-geog865-942335747.us-east-1.elb.amazonaws.com/arcgis/rest/services/RoadLimit_feature_server/FeatureServer/0/query?where=1%3D1&f=json");

You can also initialized a FeatureSet and then push the barriers as graphics:

routeParams.polygonBarriers = new FeatureSet();
routeParams.polygonBarriers.features.push(
    map.graphics.add(
        new Graphic(geometry?, symbol?, attributes?, infoTemplate?);
);

In the documentation for the RouteParameters you have more info an example in case you need it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.