Select to view content in your preferred language

Number of graphics in current view

832
5
09-26-2011 08:55 AM
DerrickMartin
Emerging Contributor
I'm looking to get the number of graphics being shown by a FeatureLayer in a map. I'm currently using the feature layer's numGraphics property which works as I would expect, until I start zooming in. I have a handler for the layer's updateEnd event which is where I check for the numGraphics value. All works as expected, but once I zoom in to a certain point the value never changes. Say I start with 500 points showing, then zoom in to a point where only 2 points are showing, the numGraphics value still shows 500. Is there another property I should be looking at? Or, should I be checking this from some other event? It looks like numGraphics does what I want, but at some point it appears as though the flex app is caching and not re-reading the map service. I'm stumped on this one. I have the layer set as a FeatureLayer in onDemand mode. Any help is greatly appreciated.
Tags (2)
0 Kudos
5 Replies
BjornSvensson
Esri Regular Contributor
I'm looking to get the number of graphics being shown by a FeatureLayer in a map.


The "numGraphics" property shows the "the number of graphics in that layer".
http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/layers/GraphicsLayer.html#numGraphics

The graphics are still there (in the layer), even when you pan and zoom (or change the visibility on the layer), and the numGraphics correctly shows this (the number of graphics in that layer).  It sounds like maybe you are looking to find out how many of those are actually within the current map extent?  And maybe also which of those are actually visible?  There is no property for that...
0 Kudos
DerrickMartin
Emerging Contributor
OK, thanks. That is exactly what I'm looking for. I had originally built an app using the javascript api and I was able get at this value using the layer.graphics.length as layer.graphics was a javascript array. However, our company uses Internet explorer extensively and the javascript api doesn't work so well with larger numbers of points being displayed. I was in the process of reworking this using Flex and got stuck here. The part that has me stumped still is that if I zoom in a little bit, it correctly changes the value to match what it being displayed, but once I zoom in past some threshold (don't know what this threshold actually is), it sticks and doesn't update. I.e. when map loads, correctly shows 2,120 as the count, zoom a little to get rid of the outermost points, and numGraphics updates to 2,065 like I expected. Zoom in a little more and it updates to 1,850... Still looks good. Zoom in to show only 3 points, and bam... numGraphics sets itself to 1,000 and won't change until I start zooming back out. Once I hit about 1,500 points, it again starts correctly showing the value. From what you are saying, this really should be showing 2,120 the whole time?
0 Kudos
BjornSvensson
Esri Regular Contributor
When using the on demand mode, you also need to be aware of the onDemandCacheSize property.
"When the query mode is MODE_ON_DEMAND and there are more than this number of features loaded, features that are not selected and are not in the current extent are removed in FIFO order (first in, first out). If this value is 0, features in the current extent are also removed.
The default value is 1000 features."

http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/layers/FeatureLayer.html#onDemandCacheSize
0 Kudos
DerrickMartin
Emerging Contributor
Thanks Bjorn! Setting this to cache size 0 makes it behave exactly how I wanted. I know this is probably not the best way to go about this but for the particular app, it's more of a reporting tool so it's working perfect for us. Thanks again!
0 Kudos
KeithWeber1
Deactivated User
I am trying to get the same functionality. I have a popup window that contains the ESRI attribute table and want to have a label underneath the attribute table that displays the number of records in the table. When I set the onDemandCacheSize property to zero, I do notice that the value of numGraphics updates, but it is not consistent with the number of features on the map or in the attribute table. Is there any other way to get this value? How is the attribute table able to get the features that are in view?
0 Kudos