Select to view content in your preferred language

map.graphics.add can not identify the graphic object

902
3
05-23-2012 12:48 AM
HarshanaDias
Emerging Contributor
Hi Mates,

I am populating rings for a Geometry json object and creating a Graphic object to add for the map. Code is looks like below,

function addGraphicToMap(geometry,ordernum,infoTemplate) {
   var new_extent = null;
   var symbol = symbols[ordernum-1];
   var graphicObj = new esri.Graphic(geometry, symbol);

   graphicObj.setGeometry(geometry);
   graphicObj.setSymbol(symbol);
   graphicObj.setAttributes( {"ORDER_NUM":ordernum});
   graphicObj.setInfoTemplate(infoTemplate);
   map.graphics.add(graphicObj);
   var old_extent = geometry.getExtent();
   if(i == 0)
   {
       new_extent = old_extent;
   }
   else
   {
      new_extent = new_extent.union(old_extent);
   }
}

But when I try to add graphicObj to map it gives me a error saying, : TypeError: 'graphicObj' is undefined

In my geometry object I have only rings as attribute and I guess that enough to create a Graphic know?

Thanks.
0 Kudos
3 Replies
ReneRubalcava
Esri Frequent Contributor
If the geometry you are passing into that function is a valid json object, you probably need to convert it to a Geometry object to create the graphic.
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/namespace_geometry.htm#fromJson
0 Kudos
HarshanaDias
Emerging Contributor
Thank you for you answer. It works. There is a another issue I came across, there are two situations where i populate this map. One is when click on edit for a saved geography and other one is populating map in the middle of a work flow of creating geography (this is the one i just figure to do correctly by this post)

So when i click on edit it execute a query with executeQueryTask and add the necessary objects to the map.graphics.add() which in other approach when i need to populate the map middle of the work flow (and i don't have saved Features in arc gis at this point to query against), I get the rings for the selected ZIPs/States and construct the necessary objects needed to map.graphics.add() as I listed in my initial post.

But when populating the map with latter approach I see the borders (differencing States etc) are not showing but with executeQueryTask  approach it shows them successfully. Initially i thought its because with executeQueryTask i set query.spatialRelationship and with other approach I didn't. But seems like its also not the problem. Can you please suggest how can i get those borders in the map?

i have attached two screen shots also how it see with and with out border in map.
0 Kudos
HarshanaDias
Emerging Contributor
I have create a new thread for latter question since its a new scenario
0 Kudos