Select to view content in your preferred language

Loop through features with already applied layer definition

1916
9
11-30-2016 11:27 PM
PitersonPaulgek
Deactivated User

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.

Tags (3)
0 Kudos
9 Replies
RobertScheitlin__GISP
MVP Emeritus

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.

0 Kudos
PitersonPaulgek
Deactivated User

Robert,

Thank you for your response.

How we do it with FeatureLayer? What mode we need to use?

example: 

mode: FeatureLayer.MODE_SNAPSHOT

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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.

0 Kudos
PitersonPaulgek
Deactivated User

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)?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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.

0 Kudos
PitersonPaulgek
Deactivated User

Robert,

Thank you very much!

Maybe the issue - the mode we use.

What mode should be fro this 

MODE_SNAPSHOT

MODE_ONDEMAND

other?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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:

  • Map properties such as the current spatial extent and time extent.
  • Layer properties such as time offset and definition expression.
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:

  1. Call the selectFeatures method.
  2. Listen for the onSelectionComplete event.
  3. Once onSelectionComplete fires, retrieve the selected features using the getSelectedFeatures method.

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_SNAPSHOTIn 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.
0 Kudos
PitersonPaulgek
Deactivated User

It just does not work!! Should the feature layer be VISIBLE?

0 Kudos
FC_Basson
MVP Regular Contributor

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.