0

I am new to the ESRI Javascript API. I do not understand what needs to go on the attr on the line with new graphic.

var graphic = new esri.Graphic(geoPoint, symbol, attr, infoTemplate); 

This is the last piece of the many samples codes i have tied together. Will someone please suggest a solution. Thank you for your help. Below is the entire function. Let me know if you need the entire script.

function onGeocodesuccess(results)
{
console.log(results);

    var geoPoint = new esri.geometry.Point(results.utm_x, results.utm_y, map.spatialReference);
    var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 15, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0,0,255]), 2), new dojo.Color([0,0,255]));
    var infoTemplate = new esri.InfoTemplate("Attributes", "${*}");
    var graphic = new esri.Graphic(geoPoint, symbol, attr, infoTemplate);
    map.graphics.add(graphic);
    map.infoWindow.setTitle(graphic.getTitle());
    map.infoWindow.setContent(graphic.getContent());
    var screenPnt = map.toScreen(geoPoint);
    map.infoWindow.show(screenPnt,map.getInfoWindowAnchor(screenPnt));


}
user1015711
  • 134
  • 1
  • 17

2 Answers2

1

Nothing is required for the "attr" variable as it is optional. In your example above I would remove the "attr" as it is not defined in the function or needed.

var graphic = new esri.Graphic(geoPoint, symbol, attr, infoTemplate);

ESRI has descent documentation for the Graphic Class.

Jeremy Hamm
  • 499
  • 1
  • 5
  • 14
0

attr is an object with keys of the fields names and values of the field values, it is generally populated with features returned from the server. When you're creating a new graphic, this is an optional parameter and as mentioned you can leave off this parameter when creating a new graphic, in your case this would be:

function onGeocodesuccess(results) {
console.log(results);

var geoPoint = new esri.geometry.Point(results.utm_x, results.utm_y, map.spatialReference);
var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 15, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0,0,255]), 2), new dojo.Color([0,0,255]));
var infoTemplate = new esri.InfoTemplate("Attributes", "${*}");
var graphic = new esri.Graphic(geoPoint, symbol);
map.graphics.add(graphic);
map.infoWindow.setTitle(graphic.getTitle());
map.infoWindow.setContent(graphic.getContent());
var screenPnt = map.toScreen(geoPoint);
map.infoWindow.show(screenPnt,map.getInfoWindowAnchor(screenPnt));

}
Tim
  • 31
  • 3