Hi,
I need to loop through features with already applied layer definition.
That means not to do additional query from a server, but get a FeatureSet from the client if possible.
Any help would be appreciated.
Piterson,
If the layer is added to the map as a FeatureLayer then yes you can just get the features on the client. If the layer you are interested in is a layer from a ArcGISDynamicMapServiceLayer then the client has no information about individual features it only has an image of the mapservice from the server.
Robert,
Thank you for your response.
How we do it with FeatureLayer? What mode we need to use?
example:
mode: FeatureLayer.MODE_SNAPSHOT
Piterson,
If the layer is added to the map as a FeatureLayer then you can get the graphics that the FeatureLayer has using the graphics property on the FeatureLayer class.
Robert,
Thank you for the response.
I see that "graphics" property has length 0.
So, what I need to do to properly loop through?
Additional question: how to loop through all features in current extent (features that currently visible on a map)?
Piterson,
The only reason I can think that the FeatureLayer.graphics would be a zero length is that you are checking the length of the graphics before the layer is finished loading. Make sure you call the FeatureLayer.graphics after the load event for the FeatureLayer has fired.
To get the graphics that are only in the maps visible extent you will have to do a query on the FL using that maps extent property.
Robert,
Thank you very much!
Maybe the issue - the mode we use.
What mode should be fro this
MODE_SNAPSHOT
MODE_ONDEMAND
other?
It depends on your needs:
MODE_ONDEMAND | In on-demand mode, the feature layer retrieves features from the server when needed. This is based on the requirements defined in the following properties:
|
MODE_SELECTION | In selection mode, features are retrieved from the server only when they are selected. Features are available on the client only while they are selected. To work with selected features:
When editing feature layers in selection mode, you will need to add the map service associated with the feature service to the map as a dynamic map service. If you do not have the map service added as a dynamic map service then the changes will not be visible because once the edits are complete the feature is no longer selected. |
MODE_SNAPSHOT | In snapshot mode, the feature layer retrieves all the features from the associated layer resource and displays them as graphics on the client. Definition expressions and time definitions are honored. The features are retrieved once the feature layer is added to the map. After the onUpdateEnd event has fired, you can access the features using the graphics property of the layer or through selection and query operations. |
It just does not work!! Should the feature layer be VISIBLE?
No, visibility is not required, but like Robert said you must wait until the features are completely loaded and the definition query set. I've tested the principle of iterating through the featurelayer graphics and it works. For my test example the MODE_ONDEMAND was used.