map.removeAllLayers Error

790
4
09-13-2013 10:06 AM
DK5
by
New Contributor III
In V3.5 I have a basemap, the default graphics layer, and I am adding another graphics layer that I allow users to draw polygons on.  Whenever I add this other graphics layer, and later try to remove it (ie. map.removeAllLayers() or map.removelayer(...)) I am getting an error back from the ArcGIS javascript:

"Unable to get property 'declaredClass' of undefined or null reference"


If I don't add this graphics layer, then the calls to remove work.  I add the layer by doing:
var newGraphicsLayer = new esri.layers.GraphicsLayer({ id: 'someIDhere' });
map.addLayer(newGraphicsLayer);

Any ideas?  Is this an official bug and is there a patch for this?
0 Kudos
4 Replies
StephenLead
Regular Contributor III
the snippets that you've posted look correct so presumably there's something else in your code which is causing the problem.

Can you link to your live site, or put the complete example on JS Fiddle, etc?
0 Kudos
DK5
by
New Contributor III
I have changed my code temporarily to not have to remove layers, so I just keep the additional graphics layer around in case it is needed again.  When I get a chance I will look into this more.  Thanks!
0 Kudos
BetsySchenck-Gardner
Occasional Contributor
For a graphics layer, have you tried using the following:
if (graphicsLayer != undefined)  graphicsLayer.clear()

I used this plenty of times with my graphic layers and it works. I have to declare the graphic layer in the map initialization section so it is recognized through the rest of my code.
0 Kudos
DK5
by
New Contributor III
Yes, I am using the clear() method on the graphics layer to allow the user to clear all the graphics on the map - that way I don't have to remove any layers.
0 Kudos