AnsweredAssumed Answered

Trouble display graphics from a GraphicsLayer

Question asked by evtguy on Sep 20, 2013
Latest reply on Sep 20, 2013 by zj_zou
I have an application that I'm trying to extend by adding the ability for my users to add a graphic point, line, or polygon and then  use that graphic as part of some analysis that I've developed. I'm using this sample's code as the basis for my code to add a user drawn graphic. This all worked fine when it was just adding the graphic to the default map graphics layer.

Because I wanted to have popups for the graphics that a user adds, I decided that I wanted to create a graphicsLayer to house any user drawn graphics. I've defined the graphicsLayer this way:

 var graphicsTemplate = new esri.InfoTemplate();  graphicsTemplate.setTitle('Custom Project');  graphicsTemplate.setContent(graphicsLayerContent);   //Define the Graphics Layer which contains the user drawn "projects"  theGLayer = new esri.layers.GraphicsLayer({   id: "gLayer",   opacity:0.80,   visible:true  });   theGLayer.setInfoTemplate(graphicsTemplate);   map.addLayer(theGLayer);


Within my application, I've set things up to basically operate like the ESRI sample I linked above. My function to add the graphic that the user draws is the following:

function addGraphic(evt) {  //deactivate the toolbar and clear existing graphics   tb.deactivate();   map.enableMapNavigation();  theGLayer.clear(); //map.graphics.clear();    // figure out which symbol to use  var symbol, g;  if ( evt.type === "point" || evt.type === "multipoint") {   symbol = markerSymbol;  } else if ( evt.type === "line" || evt.type === "polyline") {   symbol = lineSymbol;  }  else {   symbol = fillSymbol;  }    attributes = {"ProjTitle": dojo.attr("intPrjName","value"),"projLimits": dojo.attr("intPrjLimits","value")};  g = new esri.Graphic(evt, symbol, attributes, null);    theGLayer.add(new esri.Graphic(g)); //map.graphics.add(new esri.Graphic(evt, symbol)); }


My code throws no errors and adds a graphic to the graphicsLayer (theGLayer.graphics.length =1) but it isn't visible. If I add a point, the X,Y coordinates of the stored graphic point match the X,Y coordinates of the evt object and the spatialReference of the graphic matches the spatialReference of the map. Everything tells me that the layer is visible but I don't see my graphics when I add them.

What am I missing??

Thanks!
Steve

Outcomes