How do I loop through all the features in a FeatureLayer and get/set their attributes in v4 ?
Solved! Go to Solution.
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.
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.
Thanks. That worked. I didn't see graphics as a property of LayerView in the beta 3 API reference
Marc,
The Docs are still incomplete and in Beta as well.
var layerView = view.getLayerView(layer);
if (typeof layerView !== "undefined") {
layerView.graphics.forEach(function(graphic) {
//code here
});
}