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
Solved! Go to Solution.
Hi Michael,
Check out the update-end event for feature layers. I have created a quick demo here to show this in action (make sure to open a console window).
This is the results in the console window:
Hope this helps.
Hi Michael,
Check out the update-end event for feature layers. I have created a quick demo here to show this in action (make sure to open a console window).
This is the results in the console window:
Hope this helps.
That's it! I had also tried using the "update" event, but that fires every time you pan and zoom the map. "update-end" seems to only fire the one time.
Thanks very much!
Michael
Michael,
The update-end will fire with each pan/zoom if you are using FeatureLayer.MODE_ONDEMAND, but only once if you're using FeatureLayer.MODE_SNAPSHOT.
That is correct. I my case I am using SNAPSHOT mode so it only fires once, unless I have a refresh interval set, in which case it also gets fired after each refresh. I tried it with 30 minutes initially.
Thanks!