AnsweredAssumed Answered

How do to know when a featureLayer has loaded the features?

Question asked by jenkins on Jul 23, 2014
Latest reply on Jul 29, 2014 by jenkins

When I create a new FeatureLayer, I need to know when it has loaded the features into the layer.  Using the onLoad event doesn't get it because that only tells me when  "layer properties for the layer are successfully populated."

 

Watching the console. I can see that all of my JavaScript code immediately after creating the featureLayer is executed before the response from the map service comes back.  Therefore, if I use the featureLayer.on("load", function(){}) event, and tell it to count the number of features, it returns zero.   If I execute the same count a few seconds later, it returns the expected number of features.

 

Example:

MyFeatureLayer = new esri.layers.FeatureLayer(mapServiceURL, {

mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,

id: "MyFeatureLayer",

outFields: ["*"]

});

 

MyFeatureLayer.on("load", function(){

     console.log("MyFeatureLayer loaded with: " + MyFeatureLayer.graphics.length + " features");

})

 

console: MyFeatureLayer loaded with 0 features

Outcomes