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.
Solved! Go to Solution.
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.
What does the getContent function do?
Basically,
Returns the content string based on attributes and infoTemplate values.
Return value: String
It's a method of the graphic object, so it's
alert(graphic.getContent()+"Arcgis");
Sorry, I used the same syntax: graphic.getContent();
It still returns - > undefined
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.
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.
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.