Select to view content in your preferred language

Utility network samples using JS API

341
1
Jump to solution
04-20-2022 04:17 AM
KarthikAditya
New Contributor III

The JS API reference related to utility networks are here but do not have any examples. Can someone please share examples of how to get a utility network from a web map or point to a resource where they're available?

0 Kudos
1 Solution

Accepted Solutions
JoseBanuelos
Esri Contributor

Hello @KarthikAditya ,

Thanks for providing feedback on the documentation for the UtilityNetwork. I agree we are missing some sample code in this class. The code you need to load a utility network from a webmap is the following. 

const webMap = new WebMap({
  portalItem: {
    portal: { 
      url: "MyPortalUrl" 
    },
    id: "MyWebmapId" 
  }
});

webMap.when(async function() {      
  // Check if webMap contains utility networks.
  if (webMap.utilityNetworks.length > 0 ) {
    // Assigns the utility network at index 0 to utilityNetwork.
    utilityNetwork = webMap.utilityNetworks.getItemAt(0);
  }
  // Trigger the loading of the UtilityNetwork instance.
  await utilityNetwork.load();
});

 

We will add this sample code into the UtilityNetwork class. We are also working on providing a sample and some more detailed documentation on working with utility networks with the ArcGIS API for JavaScript. Thanks again for the feedback!

Thanks, 

Jose

View solution in original post

0 Kudos
1 Reply
JoseBanuelos
Esri Contributor

Hello @KarthikAditya ,

Thanks for providing feedback on the documentation for the UtilityNetwork. I agree we are missing some sample code in this class. The code you need to load a utility network from a webmap is the following. 

const webMap = new WebMap({
  portalItem: {
    portal: { 
      url: "MyPortalUrl" 
    },
    id: "MyWebmapId" 
  }
});

webMap.when(async function() {      
  // Check if webMap contains utility networks.
  if (webMap.utilityNetworks.length > 0 ) {
    // Assigns the utility network at index 0 to utilityNetwork.
    utilityNetwork = webMap.utilityNetworks.getItemAt(0);
  }
  // Trigger the loading of the UtilityNetwork instance.
  await utilityNetwork.load();
});

 

We will add this sample code into the UtilityNetwork class. We are also working on providing a sample and some more detailed documentation on working with utility networks with the ArcGIS API for JavaScript. Thanks again for the feedback!

Thanks, 

Jose

0 Kudos