Select to view content in your preferred language

How to get graphics from FeatureLayer JS 4.0beta?

4022
6
Jump to solution
07-29-2015 08:42 AM
nita14
by
Frequent Contributor

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

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
KristianEkenes
Esri Regular Contributor

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!

View solution in original post

6 Replies
AdamPfister
Esri Contributor

Hi Adam,

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.

  • There are no graphics on the FeatureLayer, use featureLayer.graphicsCollectionwhich has methods to access the graphics. For example,

               graphicsCollection.length();

graphicsCollection.getItemAt(index);

Hope that helps.

Adam

nita14
by
Frequent Contributor

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.

Regards,

Adam

0 Kudos
KristianEkenes
Esri Regular Contributor

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!

nita14
by
Frequent Contributor

Hi Kristian,

thank you for clear explanation!

Regards,

Adam

0 Kudos
Ceesvan_Altena
Deactivated User

[...]

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?

0 Kudos
KristianEkenes
Esri Regular Contributor

You should only expect updates coming with each beta release.

0 Kudos