LayerView in ArcGIS JS API 4.0beta1
Rene Rubalcava | August 30, 2015
When you try this, depending on where in the lifecycle of your application you do this, you either get an error about graphics being undefined or that graphics has a length of 0. But what the hell, you can see them on the screen damnit, don't lie to me!
Relax, this comes back to the whole idea of separating the map from the view. The map doesn't draw anything, so in turn, the layers do not draw anything, meaning they do not generate graphics. As was shown in this previous post a map can be the source for multiple views, meaning a layer can be displayed in multiple views. I hope you see where this is going, how can a layer give you a graphic count if it's shown in multiple views with different graphics visible?
There. Feel better? Cool.
So how would you get the graphics displayed in the view? You ask the view. You can use the LayerView from a view. You ask the view for the layerView that is the visual representation of the layer in the view. That's some Inception level shit right there. But once you have the LayerView, you can access the graphics.
There you go, that's how get the graphics shown in the view. Almost. Notice the surprise! comment. Right now, a view loads all the features in the service as graphics. The data is just sitting there ready to go. This might change during the beta, but right now, this doesn't help you if you want to know the count of the all the graphics displayed in the view, because you get stuff currently not displayed. But, this isn't too difficult to do on your own.
I updated an older sample to use this method you can see below.
There is one caveat to this though and that is currently, the graphics of a LayerView are only available in a 2D MapView and not a SceneView. I'm guessing because 3D gets complicated and my default answer for these cases... beta.