Select to view content in your preferred language

Add graphic (and fill attributes) to feature layer

1150
6
Jump to solution
12-01-2016 01:36 PM
by Anonymous User
Not applicable

Hi all,

I have made a buffer (project area) from roads that I would like to add to feature layer. I need to programmatically enter a start date, finish date and Name of project. I am trying the code below with an empty feature layer (made only to collect the buffers created) that already has the three attributes described up. Any idea?

featurelayerProject.applyEdits([geometry], null, null);
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

In my app, a user selects a number of features (resulting in array featureSet) and through a dialog box, changes some of the attributes. The code updates the attributes of those features and the changes are applied to the feature layer without the use of the Attribute Inspector.

array.forEach(featureSet, function (feature) {
  feature.attributes.Priority = registry.byId('cboPriority').get("value");
  feature.attributes.Management = registry.byId('cboManagement').get("value");
  feature.attributes.Criteria1 = registry.byId('cboCriteria1').get("value");
});

layerFeatureLayer.applyEdits(null, featureSet, null, function () { console.log("Features updated!"); }, function (error) { console.log("Features not updated! ", error); });

View solution in original post

6 Replies
KenBuja
MVP Esteemed Contributor

You can set the attributes of a graphic using the setAttributes method

gra.setAttributes( {"XCoord":evt.mapPoint.x,"YCoord":evt.mapPoint.y,"Plant":"Mesa Mint"});‍‍‍‍‍‍‍‍

Another way to do this is

gra.attributes.XCoord = evt.mapPoint.x;
by Anonymous User
Not applicable

That is not a bad idea except that it will be harder for me share it around. I thought of the feature layer because I can easily have it hosted in AGOL or ArcGIS Server. Also I want to achieve this programmatically because I don't want the users to deal with the attribute inspector. Maybe I can add a graphic to a feature layer? 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Alex,

   I am not sure I am following. But the featurelayerProject.applyEdits expects a graphic not a geometry.

featurelayerProject.applyEdits([geometry], null, null);
0 Kudos
by Anonymous User
Not applicable

Ha you are right Robert. I will try a graphic.

0 Kudos
KenBuja
MVP Esteemed Contributor

In my app, a user selects a number of features (resulting in array featureSet) and through a dialog box, changes some of the attributes. The code updates the attributes of those features and the changes are applied to the feature layer without the use of the Attribute Inspector.

array.forEach(featureSet, function (feature) {
  feature.attributes.Priority = registry.byId('cboPriority').get("value");
  feature.attributes.Management = registry.byId('cboManagement').get("value");
  feature.attributes.Criteria1 = registry.byId('cboCriteria1').get("value");
});

layerFeatureLayer.applyEdits(null, featureSet, null, function () { console.log("Features updated!"); }, function (error) { console.log("Features not updated! ", error); });
by Anonymous User
Not applicable

Just tried something similar and it works! Sweet. Thank you guys

0 Kudos