Issue On Rendering Result Of ESRI Request On Graphic Layer

407
9
Jump to solution
06-22-2017 09:57 AM
BehrouzHosseini
Occasional Contributor

Running following code I am able to get JSON result back from a Geometric Network Service on ArcGIS Server but I am having trouble to add the Geometries (Returened graphic) to the graphicsLayerTraceNetworkEdges can you please let me know what I am doing wrong here?

As you can see I already tried both

var graphic = new esri.Graphic(featureSet[i]);

and

var graphic = new esri.Graphic(featureSet[i], symbolTraceNetworkEdges);

but neither of the adding any graphics to the graphicsLayerTraceNetworkEdges

Here is the code I am running

var symbolTraceNetworkEdges = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 3);

var graphicsLayerTraceNetworkEdges = new esri.layers.GraphicsLayer();
var rendererTraceNetworkEdges = new esri.renderer.SimpleRenderer(symbolTraceNetworkEdges);
graphicsLayerTraceNetworkEdges.setRenderer(rendererTraceNetworkEdges);
graphicsLayerTraceNetworkEdges.setInfoTemplate(infoTemplate);
map.addLayer(graphicsLayerTraceNetworkEdges);


function solve(traceSolverType, params) {

    esri.request({
        url:agsConfig.urlGNUtility(agsConfig.operationalLayers.GNLayer, gn /* id layer from soe*/, traceSolverType /*name of operation SOE */),
        content:params,
        callbackParamName:"callback",
        load:function (result) {
            graphicsLayerTraceNetworkEdges.clear();

             var resultFeatures = result.edges;
             console.log(resultFeatures);
             for (var j = 0, jl = resultFeatures.length; j < jl; j++) {
                  var featureSet = resultFeatures[j].features;
                   for (var i = 0, il = featureSet.length; i < il; i++) {
                      //var graphic = new esri.Graphic(featureSet);  
                      var graphic = new esri.Graphic(featureSet[i], symbolTraceNetworkEdges);
                      graphicsLayerTraceNetworkEdges.add(graphic);
                            }
                        }

        });
    }
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
ThomasSolow
Regular Contributor

in your sample code, you have a variable called params that you're passing in to esri.request.  Try adding a key: "outSR" and value: 4326 to params (I assume it's a javascript object).

View solution in original post

9 Replies
ThomasSolow
Regular Contributor

Can you show an example of what featureSet looks like?

0 Kudos
BehrouzHosseini
Occasional Contributor

Thanks for reply Thomas, Please take a look at post Attachment. I just uploaded a sample return (data.json) on  `console.log(JSON.stringify(featureSet));` 

    var resultFeatures = result.edges;
    for (var j = 0, jl = resultFeatures.length; j < jl; j++) {
       var featureSet = resultFeatures[j].features;
      console.log(JSON.stringify(featureSet));
      for (var i = 0, il = featureSet.length; i < il; i++) {
       // var graphic = new Graphic(evt.geometry, config.symbolPointEBarrier);
       //var graphic = new Graphic(featureSet);
        graphicsLayerTraceNetworkEdges.add(graphic);
     }
 }‍‍‍‍‍‍‍‍‍‍
0 Kudos
ThomasSolow
Regular Contributor

Okay, I think you should create a SimpleRenderer using the symbol you're creating and pass that renderer in to the graphic layer constructor.  This will take care of the symbology for each graphic on the layer.  In the graphic constructor, use: 

 

var graphic = new esri.Graphic(featureSet)

Also, what's the spatial reference on your map?  There may be a spatial reference issue here as well.  It looks like your data uses web mercator x, y.  I notice that, in your feature JSON, there is no spatial reference property.  Something might be going with that as well.  You should check the spatial reference of a graphic after you use the esri.Graphic constructor and see what spatial reference is being assigned.

BehrouzHosseini
Occasional Contributor

You are right Thomas, 

Seems I am having issue with spatial reference!

Can you please let me know how I can force to receive the data in the correct spatial reference format?

0 Kudos
ThomasSolow
Regular Contributor

You may be able to specify the outSR (out spatial reference)  in the request that you make for features.  Try adding an { outSR: 4326 } key-value pair to your params object.

0 Kudos
BehrouzHosseini
Occasional Contributor

I am kinda confused! where should I add the outSR: 4326? 

0 Kudos
ThomasSolow
Regular Contributor

in your sample code, you have a variable called params that you're passing in to esri.request.  Try adding a key: "outSR" and value: 4326 to params (I assume it's a javascript object).

BehrouzHosseini
Occasional Contributor

You are a Rock! Thanks a lots!

0 Kudos
BehrouzHosseini
Occasional Contributor

Here also is a single format of each featureSet

  {
      "attributes":{
         "OBJECTID":1247
      },
      "geometry":{
         "paths":[
            [
               [
                  1034476.7734464034,
                  1870179.847935468
               ],
               [
                  1034476.6261717044,
                  1870189.4210841134
               ]
            ]
         ]
      }
   },
0 Kudos