<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Routing with added/scaled cost barriers in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/routing-with-added-scaled-cost-barriers/m-p/1352380#M82867</link>
    <description>&lt;P&gt;[Repost of&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-experience-builder-questions/routing-with-added-scaled-cost-barriers-in-custom/m-p/1351318#M9453" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/arcgis-experience-builder-questions/routing-with-added-scaled-cost-barriers-in-custom/m-p/1351318#M9453&lt;/A&gt;&amp;nbsp;from the Experience Builder community]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I'm trying to get routing working using the JS REST API. It will be used in a custom widget in experience builder. I got point barriers working with PointBarrier, but I need it to be added cost and it ignores everything I try. The ultimate goal is actually to use polyline barriers with scaled cost, but point barriers are simpler and neither worked.&lt;/P&gt;&lt;P&gt;Here is the code I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// variables from elsewhere
const vars = {
    // start and end point
    start, end,
    // JimuMapView
    jmv
}

const url = 'https://my-portal.com/server/rest/services/NetworkAnalysis/NAServer/Route'

const stops = new Collection([
  new Stop({
    geometry: vars.start
  }),
  new Stop({
    geometry: vars.end
  }),
])

const point = new Point({
  x: 114.168562,
  y: 22.322603
});

const start = [
  114.16853662192821, 22.323295447135724
]
const end = [
  114.16890644904946, 22.32143923097987
]
const path = [start, end]
const polyline = new Polyline({
  paths: [path]
})

const params1 = new RouteParameters({
  stops,
  pointBarriers: new Collection([
    new PointBarrier({
      geometry: point
    })
  ]),
//   pointBarriers: new Collection([
//     new NetworkFeatureSet({
//       features: [
//         new Graphic({
//           geometry: point,
//         })
//       ]
//     })
//   ]),
//   polylineBarriers: new Collection([
//     new NetworkFeatureSet({
//       features: [
//         new Graphic({
//           geometry: polyline,
//         })
//       ],
//     })
//  ])
})

route.solve(url, params1).then(r =&amp;gt; {
  const res = r.routeResults[0].route
  console.log('params1')
  console.log(r)

  const layer = new FeatureLayer({
    title: 'Route',
    source: [res],
    objectIdField: 'ObjectID',
    fields: [
      {
        name: 'ObjectID',
        type: 'oid'
      }
    ],
    renderer: {
      type: 'simple',
      symbol: {
        type: 'simple-line',
        color: 'green',
        width: '2px'
      },
    }
  })

  vars.jmv.view.map.add(layer)
})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That code has a working point barrier, but if the commented-out point barrier is used instead, it ignores the point barrier.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I use NetworkFeatureSet instead of PointBarrier as the former &lt;SPAN&gt;can carry attribute data, which should allow me to add cost to the barriers. (Or is there an alternative way to specify the cost for barrier?). I didn't specify attributes yet for the above code, because the simpler case of a completely restricted barrier isn't even working.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The second commented out code is the polyline barrier attempt using&amp;nbsp;NetworkFeatureSet, which doesn't work at all. The RouteSolveResult has null for the polylineBarrier and pointBarrier when using&amp;nbsp;NetworkFeatureSet, so it outright ignores it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I don't need to use&amp;nbsp;NetworkFeatureSet, I'll accept anything that can make routing work with added/scaled costs barriers. Thank you very much. Please let me know if I can provide additional context&lt;/P&gt;</description>
    <pubDate>Thu, 23 Nov 2023 05:39:56 GMT</pubDate>
    <dc:creator>Yik-ChingTsui</dc:creator>
    <dc:date>2023-11-23T05:39:56Z</dc:date>
    <item>
      <title>Routing with added/scaled cost barriers</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/routing-with-added-scaled-cost-barriers/m-p/1352380#M82867</link>
      <description>&lt;P&gt;[Repost of&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-experience-builder-questions/routing-with-added-scaled-cost-barriers-in-custom/m-p/1351318#M9453" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/arcgis-experience-builder-questions/routing-with-added-scaled-cost-barriers-in-custom/m-p/1351318#M9453&lt;/A&gt;&amp;nbsp;from the Experience Builder community]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I'm trying to get routing working using the JS REST API. It will be used in a custom widget in experience builder. I got point barriers working with PointBarrier, but I need it to be added cost and it ignores everything I try. The ultimate goal is actually to use polyline barriers with scaled cost, but point barriers are simpler and neither worked.&lt;/P&gt;&lt;P&gt;Here is the code I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// variables from elsewhere
const vars = {
    // start and end point
    start, end,
    // JimuMapView
    jmv
}

const url = 'https://my-portal.com/server/rest/services/NetworkAnalysis/NAServer/Route'

const stops = new Collection([
  new Stop({
    geometry: vars.start
  }),
  new Stop({
    geometry: vars.end
  }),
])

const point = new Point({
  x: 114.168562,
  y: 22.322603
});

const start = [
  114.16853662192821, 22.323295447135724
]
const end = [
  114.16890644904946, 22.32143923097987
]
const path = [start, end]
const polyline = new Polyline({
  paths: [path]
})

const params1 = new RouteParameters({
  stops,
  pointBarriers: new Collection([
    new PointBarrier({
      geometry: point
    })
  ]),
//   pointBarriers: new Collection([
//     new NetworkFeatureSet({
//       features: [
//         new Graphic({
//           geometry: point,
//         })
//       ]
//     })
//   ]),
//   polylineBarriers: new Collection([
//     new NetworkFeatureSet({
//       features: [
//         new Graphic({
//           geometry: polyline,
//         })
//       ],
//     })
//  ])
})

route.solve(url, params1).then(r =&amp;gt; {
  const res = r.routeResults[0].route
  console.log('params1')
  console.log(r)

  const layer = new FeatureLayer({
    title: 'Route',
    source: [res],
    objectIdField: 'ObjectID',
    fields: [
      {
        name: 'ObjectID',
        type: 'oid'
      }
    ],
    renderer: {
      type: 'simple',
      symbol: {
        type: 'simple-line',
        color: 'green',
        width: '2px'
      },
    }
  })

  vars.jmv.view.map.add(layer)
})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That code has a working point barrier, but if the commented-out point barrier is used instead, it ignores the point barrier.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I use NetworkFeatureSet instead of PointBarrier as the former &lt;SPAN&gt;can carry attribute data, which should allow me to add cost to the barriers. (Or is there an alternative way to specify the cost for barrier?). I didn't specify attributes yet for the above code, because the simpler case of a completely restricted barrier isn't even working.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The second commented out code is the polyline barrier attempt using&amp;nbsp;NetworkFeatureSet, which doesn't work at all. The RouteSolveResult has null for the polylineBarrier and pointBarrier when using&amp;nbsp;NetworkFeatureSet, so it outright ignores it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I don't need to use&amp;nbsp;NetworkFeatureSet, I'll accept anything that can make routing work with added/scaled costs barriers. Thank you very much. Please let me know if I can provide additional context&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2023 05:39:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/routing-with-added-scaled-cost-barriers/m-p/1352380#M82867</guid>
      <dc:creator>Yik-ChingTsui</dc:creator>
      <dc:date>2023-11-23T05:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: Routing with added/scaled cost barriers</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/routing-with-added-scaled-cost-barriers/m-p/1385236#M83706</link>
      <description>&lt;P&gt;I got it to work in ArcGIS Pro, and then applied it to JS. For polyline barriers, I just used a FeatureSet containing an array of graphics. Each graph has the attributes BarrierType=1, Attr_Minutes, Attr_Length. Minutes and Length are the names of the costs&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 02:56:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/routing-with-added-scaled-cost-barriers/m-p/1385236#M83706</guid>
      <dc:creator>Yik-ChingTsui</dc:creator>
      <dc:date>2024-02-22T02:56:39Z</dc:date>
    </item>
  </channel>
</rss>

