Get Attribute values in ArcGIS Javascript API without feature

3443
4
10-02-2014 08:27 AM
AnoopJavvadi
New Contributor

I'm creating a graphic for point to get it displayed on the map. I need to get the attribute values displayed in a pop up box, may be an infowindow will also work. The points are plotted on the map just fine but i can't see the attribute values to those points. this is the piece of code var graphic  = new Graphic( myPoint, createSymbol( iconPath, initColor ) ); graphic.setAttributes( {"Status": "test"}); map.graphics.add( graphic ); There are like 100 points and so i'm running the a "for loop" for each point so that they can be added to the map. Similarly at the same time i'm assigning the attribute values to it. How to get those values ?? I tried to get the attribute values using: alert(getContent()+" Arcgis"); But in the alert window it returns:          "undefined ArcGIS" It is returning the undefined value. It will be of a great help if anyone can help me out on this one.

0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor

Can you post the code you're using? That would make it much easier to help you.

0 Kudos
AnoopJavvadi
New Contributor

function pinMap( ) {

                $.post( '{{ path( 'points' ) }}', {}, function( r ) {

                    arrayUtils.forEach( r.points, function( point ) {

                            var iconPath  = "M15.834,29.084 15.834,16.166 2.917,16.166 29.083,2.917z";

                            var initColor = "#CF3A3A";

                        var graphic   = new Graphic( new Point( point.coords ), createSymbol( iconPath, initColor ) );

                        graphic.setAttributes( {"Status": "test"});

                        map.graphics.add( graphic );

                        var conc = getContent();

                        alert(conc+" ArcGIS");

                        map.graphics.on("click", addPoint);            

                    } );

                }, 'json' );

            }

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Hi Anoop,

Try assigning the attribute when you create the graphic.  Ex:

var sfs = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,

        new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,

        new Color([255,0,0]), 2),new Color([255,255,0,0.25])

)

var singleRingPolygon = new Polygon([[-75.77, 38.45], [-75.77, 38.7], [-75.11, 38.7], [-75.11, 38.45], [-75.77, 38.45]])

var attr = {"Area":"Southern Delaware"};

var infoTemplate = new InfoTemplate("Location","Area: ${Area}");

var gra = new Graphic(singleRingPolygon, sfs, attr, infoTemplate);

map.graphics.add(gra);

0 Kudos
AnoopJavvadi
New Contributor

Hi Jake,

I tried a similar way but it still returns as "undefined"
This is what i used,

var attr = {"Xcoord":"test","Ycoord":"test1","Plant":"Mesa Mint"};

var graphic   = new Graphic( new Point( point.coords ), createSymbol( iconPath, initColor ), attr );

nums.push(graphic.getContent());

map.graphics.add( graphic );

map.graphics.on("click", addPoint);

} );

console.log(nums);

0 Kudos