How to delete line ?

1841
4
11-23-2010 10:21 PM
zeeshanbhatti
New Contributor
i am drawing line using this code reference from

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm

var myLine ={geometry:{"paths":[[[-91.40625,6.328125],[6.328125,19.3359375]]],
  "spatialReference":{"wkid":4326}},
  "symbol":{"color":[0,0,0,255],"width":1,"type":"esriSLS","style":"esriSLSSolid"}};
var gra= new esri.Graphic(myLine);
map.graphics.add(gra);

How can i delete the line if i am trying to draw in above mention way.
The samples for deleting graphics method is not clear if we are drawing using inputs parameters. Can some one help us through code.
0 Kudos
4 Replies
timgogl
New Contributor II
i dont know of a delete function for objects in javascript, but you might try:

var gra= new esri.Graphic(myLine);
map.graphics.add(gra);

gra.hide(); // hide the graphic
gra=null;


setting it to null 'should' let the js engine know that the object is available for garbage collection, whether it gets collected or not.. who knows.
0 Kudos
timgogl
New Contributor II
well, this is why i like to read through the forums here, i get to learn new things....


looking at this post: http://forums.arcgis.com/threads/17871-Trouble-with-routing?p=57167&posted=1#post57167

i noticed this user using a remove() method on a graphics object.... so that maybe what you need to use.

heh. ah.. just found the documentation, its under GraphicsLayer, not graphics.

http://help.arcgis.com/EN/webapi/javascript/arcgis/help/jsapi_start.htm
0 Kudos
JohnFreels
New Contributor
You could use the Map.Graphics layer for drawing.  That's what I do.  Call 'map.graphics.clear()' to get rid of them to clear the interface or for redrawing. 

Could this solution work for you?
0 Kudos
zeeshanbhatti
New Contributor
Well i have solved it .I have declared a global array and pushed all the graphic retreived from database along with unique ID. Then i have removed the desired graphic by using Map.Graphic.Remove(graphic_Line[Id]). Method. And it works for me.

Thanks to All

Regards,
Zeeshan
0 Kudos