Loop through features in FeatureLayer

4596
4
Jump to solution
03-10-2016 10:33 AM
MarcBate
Occasional Contributor II

How do I loop through all the features in a FeatureLayer and get/set their attributes in v4 ?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Marc,

  You can get the graphics from the layers view:

// Carbon storage of trees in Warren Wilson College.
        var featureLayer = new FeatureLayer({
          url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"
        });


        featureLayer.on("layer-view-create", function(evt){
          //The LayerView for the layer that emitted this event
          console.info(evt.layerView);
        });

The layerView has a graphics property.

But be aware of this note in the docs:

In this version of the API, geometries and attributes of features in a FeatureLayer cannot be added, deleted, or edited.

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Marc,

  You can get the graphics from the layers view:

// Carbon storage of trees in Warren Wilson College.
        var featureLayer = new FeatureLayer({
          url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"
        });


        featureLayer.on("layer-view-create", function(evt){
          //The LayerView for the layer that emitted this event
          console.info(evt.layerView);
        });

The layerView has a graphics property.

But be aware of this note in the docs:

In this version of the API, geometries and attributes of features in a FeatureLayer cannot be added, deleted, or edited.

0 Kudos
MarcBate
Occasional Contributor II

Thanks. That worked.  I didn't see graphics as a property of LayerView in the beta 3 API reference

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Marc,

  The Docs are still incomplete and in Beta as well.

0 Kudos
MarcBate
Occasional Contributor II

var layerView = view.getLayerView(layer);
if (typeof layerView !== "undefined") {

  layerView.graphics.forEach(function(graphic) {

       //code here

  });

}

0 Kudos