Select to view content in your preferred language

Problems adding attributes to a graphic

2572
3
Jump to solution
12-12-2014 06:47 AM
TracySchloss
Frequent Contributor

I am buffering points and I want to put the attributes of original point on the resultant buffer polygon.  I also want to add an extra attribute for 'source' to indicate which layer I was buffering. 

The graphic is getting the feature.attributes from the original point.  I thought I could use graphic.attr('name','value') to add the extra attribute I want.  It doesn't seem to be doing anything.  It's not generating any error either.  Is this not the proper method?

//create a buffer graphic for every point
function generateBufferGraphic(features){
    bufferLayer.clear();  
  var radius = registry.byId("bufferSelect").value;//user can select buffer distance 
  var idPoint,circle;
  arrayUtils.forEach(features, function (feature){
    idPoint = feature.geometry;
     circle = new Circle({  
        center: idPoint,  
        geodesic: true,  
        radius: radius,  
        radiusUnit: "esriMiles"  
     });  
      var graphic = new Graphic(circle, bufferSymbol,feature.attributes);  
      graphic.attr('source','layername');
      bufferLayer.add(graphic);  
  });
}
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You have to set the attributes of a graphic with this syntax

//is layername a string or a variable in your code? This assumes it a variable
graphic.attributes.source = layername

View solution in original post

0 Kudos
3 Replies
KenBuja
MVP Esteemed Contributor

You have to set the attributes of a graphic with this syntax

//is layername a string or a variable in your code? This assumes it a variable
graphic.attributes.source = layername
0 Kudos
TracySchloss
Frequent Contributor

That works, thanks.  I'm not sure what the documentation means for the syntax I was trying. 

0 Kudos
KenBuja
MVP Esteemed Contributor

I ran into the same issue, which is how I got this answer. I agree that the documentation needs to be clarified.

0 Kudos