Utility Network Trace results

848
11
11-20-2023 04:03 AM
NarendranathMandal
New Contributor II

When running the Utility network trace widget, the results will be added as graphics.

How to get the graphics results data in the console ? 

I tried to trigger the events which is documented in the api documentation  add-result-area. But the event is not working.

Here my code is below

utilityNetworkTrace.on('add-result-area', getResult)
 
function getResult() {}
 
Reference URL
 
 
0 Kudos
11 Replies
AlixVezina
Esri Regular Contributor

@NarendranathMandal , right now the result graphics are only created when they are shown in the view, see #resultAreaProperties

AlixVezina_0-1700493236597.png

Could that be the reason you are not getting the results in the console?

0 Kudos
NarendranathMandal
New Contributor II

I have included that show properties in UtilityNetworkTrace. But still I am not getting the graphics results in the console.

0 Kudos
AlixVezina
Esri Regular Contributor

Also refer to related post: Utility Network Trace Result - Esri Community

0 Kudos
AlixVezina
Esri Regular Contributor

@NarendranathMandal Many people are out of the office this week, we'll get back to you with a resolution or more questions next week.

0 Kudos
PrevinWong1
Esri Contributor

@NarendranathMandal can you confirm that a polygon result area is drawn in the map after a trace is run and you toggle on the result area?

Also in your function, you need a parameter since the event emits a graphic.

function getResult(graphic) {console.log(graphic)}

0 Kudos
NarendranathMandal
New Contributor II

Yes .  a polygon result area is drawn in the map , Only the function is not getting trigger . 

0 Kudos
NarendranathMandal
New Contributor II
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>
      UtilityNetworkTrace widget | Sample | ArcGIS Maps SDK for JavaScript 4.28
    </title>

    <link
      rel="stylesheet"
    />
    <script src="https://js.arcgis.com/4.28/"></script>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>
    <script>
      require([
        "esri/WebMap",
        "esri/views/MapView",
        "esri/widgets/UtilityNetworkTrace",
        "esri/config",
        "esri/widgets/LayerList",
        "esri/core/reactiveUtils"
      ], (WebMap, MapView, UtilityNetworkTrace, esriConfig, LayerList, reactiveUtils) => {
        // Set the hostname to the on-premise portal
        // Enterprise example: esriConfig.portalUrl = "https://myHostName.esri.com/arcgis";
        esriConfig.portalUrl = "https://www.arcgis.com"; // this is the default

        // Initialize the WebMap and pass in the webmap id
        // Credentials to sign in to the webmap:
        // username: viewer01
        // password: I68VGU^nMurF
        const webmap = new WebMap({
          portalItem: {
            // autocasts as new PortalItem()
            id: "471eb0bf37074b1fbb972b1da70fb310" // webmap id
          }
        });

        // Initialize the view
        const view = new MapView({
          container: "viewDiv",
          map: webmap
        });

        const layerlist = new LayerList({
          view: view
        })

        view.ui.add(layerlist, {position: 'top-left'})

        // Initialize the UtilityNetworkTrace widget without any set parameters
        const utilityNetworkTrace = new UtilityNetworkTrace({
          view: view,
         
        });
       
        // Add the widget to the view
        view.ui.add(utilityNetworkTrace, "top-right");
        utilityNetworkTrace.on('add-result-area', test) // working
        //utilityNetworkTrace.on('add-result-area', test) // not working
        reactiveUtils.watch(() => view.layerViews, () => {
          alert('testing')
        })
        function test(graphic){
          console.log(graphic)
          alert('testing')
        }
       
      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
  </body>
</html>
 
 
This is the code for your reference .
The fuction itself is not getting call
0 Kudos
PrevinWong1
Esri Contributor

In your UtilityNetworkTrace constructor, make sure you have enableResultArea defined and set to TRUE.  The you will see the result area toggle, at which point, if you toggle, it fires the callback.  See images below.

      const utilityNetworkTrace = new UtilityNetworkTrace({
        view: view,
        enableResultArea: true
      });
 
0 Kudos
NarendranathMandal
New Contributor II

Thank You , I got the area . Any idea how i can get the atributes print in the console or export the atributes from the trace result ?

0 Kudos