Hello,
Does anybody know how to get graphics (ie, fields values) from FeatureLayer? After having added feature service to the SceneView, featureLayer.graphics.length returns 0.
Thanks
Adam
Hi Adam and Adam,
The documentation on this is misleading and, in the cases you both brought up, contradictory. The reason for this is because the way these workflows are being designed has been changing and will continue to change as 4.0 progresses through multiple betas into the final product. The documentation reflects some of these changes over time, but isn't consistent with how things are now. We are updating it so that it will not be as confusing.
featureLayer.graphicsCollection does not exist. The Migration page in the guide is wrong and will be updated soon. featureLayer.graphics exists, but as the original post mentions, doesn't actually do anything. This too will likely go away and accessing graphics on the view will change in the future. Stay tuned for documentation updates explaining this. There are a number of reasons featureLayer.graphics will no longer be used, the primary reason being that features are no longer rendered on the layer or the map; rather, they are rendered in the LayerView and View. This is a major difference between our 3.x and 4.x APIs, so keep a look out for updated documentation, blogs, etc that go into greater depth explaining these concepts and classes.
In the interim you can access the graphics displayed in the view via the 'graphics-controller-create' event on the featureLayer. This is undocumented, but will be later. The event object has a graphicsController property, which is an object that has a graphicsCollection property. See this jsbin for an example of accessing the graphics using one of our existing samples: JS Bin - Collaborative JavaScript Debugging
I hope this helps!
[...]featureLayer.graphicsCollection does not exist. The Migration page in the guide is wrong and will be updated soon. featureLayer.graphics exists, but as the original post mentions, doesn't actually do anything. This too will likely go away and accessing graphics on the view will change in the future. Stay tuned for documentation updates explaining this. [...] This is a major difference between our 3.x and 4.x APIs, so keep a look out for updated documentation, blogs, etc that go into greater depth explaining these concepts and classes.
[...]
featureLayer.graphicsCollection does not exist. The Migration page in the guide is wrong and will be updated soon. featureLayer.graphics exists, but as the original post mentions, doesn't actually do anything. This too will likely go away and accessing graphics on the view will change in the future. Stay tuned for documentation updates explaining this. [...] This is a major difference between our 3.x and 4.x APIs, so keep a look out for updated documentation, blogs, etc that go into greater depth explaining these concepts and classes.
Hi Kristian,
Thank you for this relatively in-depth answer. Can you tell us more about the beta release cycle? Will all the updates be pushed iterative or do we have to wait for all these changes for the next beta release?
thank you for clear explanation!
Regards,
Hi Adam,
thank you for this quick reply. I forgot about simple RTFM! However, i can not access graphicsCollection property of my feature layer (feature service hosted in agol), it does not exist. There are only graphics and graphicsSource properties.
For now i decided to bypass it using query and queryTask.
According to the migration guide (Migrating from 3.x to 4.0 | ArcGIS API for JavaScript ), the graphics are now at the graphicsCollection property of the FeatureLayer.
FeatureLayer
featureLayer.graphicsCollection
graphicsCollection.length();
graphicsCollection.getItemAt(index);
Hope that helps.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.