Select to view content in your preferred language

Get Attribute values in ArcGIS Javascript API without feature layer

6918
7
Jump to solution
10-02-2014 08:32 AM
AnoopJavvadi
Deactivated User

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
1 Solution

Accepted Solutions
TracySchloss
Honored Contributor

The definition of getContent on a graphic says

Returns the content string based on attributes and infoTemplate values

You don't have an infoTemplate defined, only attributes.  That's why getContent is failing. 

If you plan is to use the information to show a popup or infoWindow, you'll need something like an infoTemplate anyway to define how your tag comes up. 

View solution in original post

7 Replies
KenBuja
MVP Esteemed Contributor

What does the getContent function do?

0 Kudos
AnoopJavvadi
Deactivated User

It belongs to the graphic object. You can find the details here:

graphic-amd | API Reference | ArcGIS API for JavaScript

Basically,

getContent()

Returns the content string based on attributes and infoTemplate values.

Return value: String

0 Kudos
ReneRubalcava
Honored Contributor

It's a method of the graphic object, so it's

alert(graphic.getContent()+"Arcgis");

0 Kudos
AnoopJavvadi
Deactivated User

Sorry, I used the same syntax:      graphic.getContent();
It still returns - > undefined

0 Kudos
TracySchloss
Honored Contributor

If there is something wrong with the graphic before you add attributes, there's already an issue before you get to the setAttributes line.  Could you also provide the definitions for the variables you're using like iconPath, myColor etc. 

0 Kudos
AnoopJavvadi
Deactivated User

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 = graphic.getContent();

                        alert(conc+" ArcGIS");

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

                    } );

                }, 'json' );

            }

function createSymbol( path, color ) {

                var markerSymbol = new esri.symbol.SimpleMarkerSymbol( );

                markerSymbol.setPath( path );

                markerSymbol.setColor( new dojo.Color( color ) );

                markerSymbol.setOutline( null );

                return markerSymbol;

            }

This is the code I'm using.

0 Kudos
TracySchloss
Honored Contributor

The definition of getContent on a graphic says

Returns the content string based on attributes and infoTemplate values

You don't have an infoTemplate defined, only attributes.  That's why getContent is failing. 

If you plan is to use the information to show a popup or infoWindow, you'll need something like an infoTemplate anyway to define how your tag comes up.