Create utility network diagram using REST API

848
1
05-31-2022 05:19 AM
KarthikAditya
New Contributor III

I'm trying to create a network diagram based on the Basic diagram template for a utility network feature using createDiagramFromFeatures endpoint Create Diagram From Features—ArcGIS REST APIs | ArcGIS Developers

I get a response of the form Diagram Information object but I'm not sure how to convert this JSON object into an actual network diagram that can be visualized on a map that is created using JavaScript API.

There is the fromJSON method that can create an instance of the given class from JSON. But, it looks it is supported only for certain types like -  symbols , geometries , FeatureSet. Can this method be used to create a network diagram from Diagram Information JSON?

Any suggestions or examples related to this would be really helpful

0 Kudos
1 Reply
AnneYvonneBlin
Esri Contributor

Hi @KarthikAditya 

We do not have any public Network Diagram JavaScript API yet. However, you can develop your WebApp in JavaScript and visualize the newly generated diagram you expect. To do so, you can follow the guidance below:

First of all, regarding our REST API, the createDiagramFromFeatures operation returns a Diagram Information Object with the diagram Name given by default to this new diagram.
This is this default name <diagramName> that you can use to retrieve the new diagram among all the diagrams that currently exist in the dataset, https://<networkdiagrams_url>/<diagramName> and then build the diagram map url for this specific diagram.

As an attached file, please find a sample Network Diagrams WebApp that  exemplifies how you can create and display a network diagram using JavaScript code.
For this sample WebApp, the 1st workflow step is to connect to a utility network service. This makesthe related network data to load in a network map. Then, when users click btnGenerateFromExtent (See line#329 in NetworkDiagramsSampleWebApp.html), the code retrieves the GlobalID of all the network features currently visible in this network map and creates a diagram from this network feature set (see cloneTemporaryDiagram code starting at line#198 in networkdiagram.js.)
Then, starting from the default diagram name (diagramName = res.diagramInfo.name), we build the diagram map URL (see getDiagramMapUrl at line#142 in networkdiagram.js.) and display this map (see displayDiagram at line#300 in NetworkDiagramsSampleWebApp.html).

Hopping this helps
Anne-Yvonne