0

I have a list of features that I would like to add to a layer. The features are built from a list of objects that contain a number of attributes as well as a set of coordinates.

var lines = data; //Data represents the object list

for( var count = 0; count<lines.length; count++)
{                            

   if (lines[count] != null) {
      var latitude = lines[count].latitude;
      var longitude = lines[count].longitude;                               

      var pt = new Point(xy[0], xy[1], new SpatialReference({ wkid: app.map.spatialReference.wkid }));
      pt.attributes = {};
      //Code to set each attribute is here
      pt.attributes.attributeName = attributeValue //Taken from the data list for each value - left out all data transfers to preserve space


     var graphic = new esri.Graphic(pt, null, pt.attributes);
     Layer.applyEdits([graphic], null, null);                                  
                            }
                        }
                    }
                }

The process works and each feature is drawn on the map, however the process is super slow. Accessing the console window throws no errors and ArcGIS Server manager also throws no errors. However checking the network tab in the developer window shows a list of apply edit functions pending, waiting them all out for a list of around 100 can take around an hour which is too long.

Is there some kind of process that is slowing this down? Since debugging my code reveals no issues, the issue seems to be once the apply edit functionality is called for all the features

1

You're firing applyEdits for each feature in the for loop. You should move that outside the for loop so that it happens once

var lines = data; //Data represents the object list
var graphics = [];
for( var count = 0; count<lines.length; count++)
{                            

   if (lines[count] != null) {
      var latitude = lines[count].latitude;
      var longitude = lines[count].longitude;                               

      var pt = new Point(xy[0], xy[1], new SpatialReference({ wkid: app.map.spatialReference.wkid }));
      pt.attributes = {};
      //Code to set each attribute is here
      pt.attributes.attributeName = attributeValue //Taken from the data list for each value - left out all data transfers to preserve space


      var graphic = new esri.Graphic(pt, null, pt.attributes);
      graphics.push(graphic);                                  
   }
}
Layer.applyEdits(graphics, null, null);                                  
  • This seemed to do the trick, as all the features were being drawn within a minute of so depending on the number of features within the array. Thanks! – Maeglin77 May 7 '18 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.