If the Graphic is added directly to the map, you can just call map.graphics.remove(the_graphic)
, where the_graphic
is the graphic that you want to remove.
You can also call map.graphics.clear();
to remove all graphics added in this way.
If you have added graphics to a particular graphics layer, then you need to remove the graphic from that particular layer, by calling something like gLayer.remove(the_graphic)
where gLayer
is your graphic layer and the_graphic
is the graphic that you want to remove.
For completeness sake, if you want to remove all graphics contained in the map, you can use the following function:
function clearGraphics() {
//first remove all graphics added directly to map
map.graphics.clear();
//now go into each graphic layer and clear it
var graphicLayerIds = map.graphicsLayerIds;
var len = graphicLayerIds.length;
for (var i = 0; i < len; i++) {
var gLayer = map.getLayer(graphicLayerIds[i]);
//clear this Layer
gLayer.clear();
}
}