cleared graphics re-appear

604
2
01-13-2011 01:19 PM
Kathleen_Crombez
Occasional Contributor III
I created a graphics layer for the drawing toolbar tools.

var drawing = new esri.layers.GraphicsLayer({});

when I call drawing.clear(); the graphics are removed from the screen.
but after I pan, zoom in / out, or try to print the graphics are visible again?

the strange thing is that drawing.graphics.length is zero.

is this a caching issue?

my development site is at http://www.maps.ccgisc.org/test/

thanks.
0 Kudos
2 Replies
JeffHoward
New Contributor II
I too ran across this last week. Everything looks fine in layout view and even the print preview, but when printing or exporting the mxd a previously deleted graphic reappears in the print copy.
0 Kudos
Kathleen_Crombez
Occasional Contributor III
I figured out what I was doing wrong.

when I was adding the graphic to the drawingGraphicsLayer I was calling drawingGraphicsLayer.add(map.graphics.add(graphic));

so essentially, I was adding the graphic to both the drawingGraphicsLayer and the default GraphicsLayer map.graphics

I think the reason I did this was because I was calling map.addLayer(drawingGraphicsLayer); before the map was loaded which caused a JScript runtime error "this._cg._surface" is null or not an object.

I found the solution here: http://forums.esri.com/Thread.asp?c=93&f=2396&t=284131&g=1

Seems like (unlike most layers) you have to wait for the map to load before adding a new GraphicsLayer

drawingGraphicsLayer = new esri.layers.GraphicsLayer();

dojo.connect(map, "onLoad", function() {
   map.addLayer(drawingGraphicsLayer));
});
0 Kudos